I have a matrix 'a' and i want to calculate the distance from one point to all other points. So really the outcome matrix should have a zero (at the point I have chosen) and should appear as some sort of circle of numbers around that specific point.
Mostrar comentarios más antiguos
% this is what i have so far but its not showing me what i want. I cant figure out what im doing wrong.
%any suggestions would be extremely helpful. Thank you in advance :)
a = [1 2 3 4 5 6 7 8 9 10]
for i = 2:20
a(i,:) = a(i-1,:) + 1;
end
N = 10
for I = 1:N
for J = 1:N
dx = a(I,1)-a(J,1);
dy = a(I,2)-a(J,2);
distance(I,J) = sqrt(dx^2 + dy^2)
end
end
2 comentarios
Yatin
el 18 de Oct. de 2013
Is the vector a, the set of all points that you have? I am not able to understand what are you trying to do in the first for loop by creating a matrix of 20 rows. Can you explain in more details as to what are you trying to achieve here?
sony
el 18 de Oct. de 2013
Respuesta aceptada
Más respuestas (1)
Image Analyst
el 18 de Oct. de 2013
Do you mean like this:

% Make a set of 50 points
x = rand(1, 50);
y = rand(1, 50);
% Now make a point that we want to use as the reference
% from which we will calculate distances and plot them.
xCenter = mean(x);
yCenter = mean(y);
% Now find the distances
distances = sqrt((x-xCenter).^2+(y-yCenter).^2)
% Now plot the lines
for k = 1 : length(x)
% Plot the line
line([x(k), xCenter], [y(k), yCenter], 'LineWidth', 3);
if k == 1
hold on;
end
% Plot the endpoints as markers.
plot(x(k), y(k), 'or', 'LineWidth', 3);
end
% Plot the reference point as a marker.
plot(xCenter, yCenter, 'or', 'LineWidth', 3);
grid on;
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Give a name to the title bar.
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
2 comentarios
Image Analyst
el 18 de Oct. de 2013
Or maybe you mean this: http://matlab.wikia.com/wiki/FAQ?&cb=1314#How_do_I_create_a_circle.3F Why don't you explain your question better and include a screenshot of what you'd like to obtain?
sony
el 18 de Oct. de 2013
Categorías
Más información sobre Univariate Discrete Distributions en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!