I'm trying to write a function that will calculate the distance between points in a 2D matrix, calculate a distance type, and then show a visual version of the matrix with a line between the two points fed as parameters with the distance. Only the points fed as parameters should be colored in the output matrix, and there should be a grid.
My code is:
function[resultIm dist] = find_show_distance(inputMat, loc1, loc2,
distType)
[rows, cols] = size(inputMat);
resultIm = zeros(rows, cols);
switch distType
case 0
dist = sqrt((loc2(1) - loc1(1))^2 + (loc2(2) - loc1(2))^2);
case 1
dist = max((loc1(1) - loc2(1)), (loc1(2) - loc2(2)));
otherwise
dist = abs(loc1(1) - loc2(1)) + abs(loc1(2) - loc2(2));
end
resultIm(loc1) = 4;
resultIm(loc2) = 155;
image(resultIm);
dist
end