2

In Matlab I have two Nx3 matrices P and Q and each line represents a point. I want to plot lines between the points that are in the same row of the matrices.

Following Code does it:

for i=1:N
  plot3( [P(i,1) Q(i,1)], ...
         [P(i,2) Q(i,2)], ...
         [P(i,3) Q(i,3)] )
end

Is there a way to do it without a for-loop?

If I give plot3 the points just as vectors, Matlab draws lines between Q(i,:) and P(i+1,:) in addition to the lines I want.

2 Answers 2

4

Try

plot3([P(:, 1) Q(:, 1)]', ...
      [P(:, 2) Q(:, 2)]', ...
      [P(:, 3) Q(:, 3)]')

If you feed a matrix to the Matlab plotting functions, each column corresponds to one line drawn.

Sign up to request clarification or add additional context in comments.

Comments

0

Probably you want this:

h = quiver3(P(:,1), P(:,2), P(:,3), Q(:,1), Q(:,2) , Q(:,3),0);

set(h,'ShowArrowHead','off');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.