0
votes

I have two matrix as

A = [1 2 3; 4 6 7; 3 6 7]
B = [2 5 6; 2 8 7; 2 8 5]

I want to plot a graph between this two matrix, I mean in such as way that A(1,1) as x coordinate and B(1,1) as Y coordinate of 1st point. Similarly, for 2nd point A(1,2) as x and B(1,2) as Y and so on. At last I should get straight line connecting this point for each row.

And then I have the measure the length of the line connecting all the points for each row, so that I can know which row have greater length

I tried this

    for i=1:1:3
    plot(A(i,:),B(i,:)), hold on;
    end

Is it correct because I can't able to interpret and how to measure the length also??

2

2 Answers

1
votes

Your way of plotting seems correct.

To calculate the length of each line I would use this code:

for i=1:1:3
  len(i) = sum(sqrt(diff(A(i,:),1).^2+diff(B(i,:)).^2));
end
1
votes

You don't need for loop to plot. Just do.

A = [1 2 3; 4 6 7; 3 6 7];
B= [2 5 6; 2 8 7; 2 8 5];

% Plot lines
plot(A.',B.');

% Calculate length of lines
length=sum(sqrt((diff(A,1,2).^2)+(diff(B,1,2).^2)),2);