James07
Computer
- Nov 5, 2005
- 1
Hi to all, i am basically a newbie in MATLAB and i have written some code that i would think should go through a matrix and write the values i want in.
W = zeros(150);
% Give values to the 150 values of M so that we have
% 150 (x,y) to make the dataset
M = rand(2,150) * 10;
% Create the matrix
for z = 1:149
for v = 1:149
y_total = (M(2,v+1) - M(2,v))^2;
x_total = (M(1,v+1) - M(1,v))^2;
W(z,v) = sqrt((y_total + x_total)\s^2);
end
end
************************************************
Here, my idea was that i have 150 opints on a graph and all the points are held in M(a column for each x,y point). Then i would want to find the distance between each two points by doing the Pythagoras theorem in W(z,v) and store the data in the appropriate rows and columns in W. My final result is that i get the same number written 150 times in each row of the same column. What am i doing wrong? Thanks for the help
W = zeros(150);
% Give values to the 150 values of M so that we have
% 150 (x,y) to make the dataset
M = rand(2,150) * 10;
% Create the matrix
for z = 1:149
for v = 1:149
y_total = (M(2,v+1) - M(2,v))^2;
x_total = (M(1,v+1) - M(1,v))^2;
W(z,v) = sqrt((y_total + x_total)\s^2);
end
end
************************************************
Here, my idea was that i have 150 opints on a graph and all the points are held in M(a column for each x,y point). Then i would want to find the distance between each two points by doing the Pythagoras theorem in W(z,v) and store the data in the appropriate rows and columns in W. My final result is that i get the same number written 150 times in each row of the same column. What am i doing wrong? Thanks for the help