At Image or others: Distance from points to point.

 Akzeptierte Antwort

Image Analyst
Image Analyst am 9 Feb. 2014
I thought I already showed you in your duplicate question http://www.mathworks.com/matlabcentral/answers/115335#comment_195217. I don't know what gplot() is - I never use it. I showed you how you could use plot() to pass in a color. You just need to assign the color. For example
if distance > gvar(i)
plot(x,y, 'ro-'); % Plot red circles.
else
plot(x,y, 'bs-'); % Plot blue squares.
end
By the way, your loop over i and j is calculating all the distances twice, unlike how I showed you. The distance from point 1 to point 3 is the same as from point 3 to point 1 so why calculate it again?

6 Kommentare

But If you note, with the plot command you delete the square. I do not want this. I do not want to delete the square that contains the coordinates of points. The distances between the various coordinates are already in memory. I just want to highlight those I am interested to .With the plot command you eliminate the spatial information of where these points are contained in the square.
Fine. Keep them if you need them later. It's only a few points so it won't take any time at all. The comparison of the distance to the gvar distances to determine color still holds though, don't you agree? To determine a color like you want, you MUST compare the distance to the distances associated with each color. There is no other way. How else will you know what color to use?
The question of color is not important because it is related in the values of the variable val_mag. You have to consider this: The first value of val_mag is the distance between 0.2 and 0.3 to 0.7 and 0.4. The second value of the val_mag variable is associated with the distance between 0.2 and 0.3, to 0.45 and 0.37. The third value of the val_mag variable is associated with the distance between 0.2 and 0.3 and 0.1 and 0.6 and so on. All these distance have to point out in red. The others distances don't matter. You know what distances should be highlighted in red because this information is contained in the element of val_mag greater than zero. Is not clear?
>> val_mag
val_mag =
0.3366
0
0.1766
It's not clear why you can't adapt my answer to get it to work. Why can't you just isert this code and have it work:
if dist(i,j) > val_mag(i) % or gvar - whatever it's called.
plot(x,y, 'ro-'); % Plot red circles.
else
plot(x,y, 'bs-'); % Plot blue squares.
end
You just figure out what x and y are for the pair of points you're considering and draw the correct color.
??? Attempted to access val_mag(9); index out of bounds because numel(val_mag)=3.
Now there is this error code line.
Well how did the index get to 9? Are you using the debugger at all? Or just wanting me to download your code and data and have me debug it for you?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by