×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Code seems to do the same thing over again

Code seems to do the same thing over again

Code seems to do the same thing over again

(OP)
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 :)

RE: Code seems to do the same thing over again

Well if I were you I'd write a very stern letter to Mathworks and let them know that the program is doing exactly what you asked it to, instead of what you wanted.


Try

for z = 1:150
        
    for v = 1:150
       y_total = (M(2,z) - M(2,v))^2;
       x_total = (M(1,z) - M(1,v))^2;
       W(z,v) = sqrt((y_total + x_total)\s^2);    

    end
end


Cheers

Greg Locock

Please see FAQ731-376 for tips on how to make the best use of Eng-Tips.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources