0
votes

What is wrong with this piece of code?

plot3(X,Y,Z,'r');
hold on
plot3(Xs,Ys,Zs,'g');

Why do I only get one plot? If I try to draw them separately, both draw just fine.

1
It looks fine, and it should work. Can you please expand a little with a small sample data that can replicate the error, a rough image of what you expect, and what you get. - Noel Segura Meraz
Works for me with X = [1 2 3]; Y = [1 2 3]; Z = [1 2 3]; Xs = 4+[1 2 3]; Ys = 4+[1 2 3]; Zs = 4+[1 2 3]; - Jørgen
This could be also a scaling issue. What are the ranges of all your variables? - EBH
@EBH first set I can't even predict - I'm messing with Bezier curves and have to use some stupid formula that does not even work, the second set just describes random points inside 0:5,0:5,0:5 cube. - Barsik the Cat
Type [min(X(:)) max(X(:))] before plotting, and see what is the range of your values with respect to Xs. do so for Y and Z as well, and see if their range is from the same order, or one is very small compared to the other so you can't see him - EBH

1 Answers

0
votes

Your question is quite vague. It's not clear if you want to plot 2 sets of data on the same axes (for that your code is fine), or you want to plot to different axes on the same figure.

Assuming your data looks like this:

X = 0:0.1:100;
Y = sin(X);
Z = cos(X);
Xs = 0:0.1:100;
Ys = cos(X);
Zs = sin(X);

For the first option you would write:

plot3(X,Y,Z,'r');
hold on
plot3(Xs,Ys,Zs,'g');
hold off

and get:

enter image description here

and for the second option you would write:

subplot 211
plot3(X,Y,Z,'r');
subplot 212
plot3(Xs,Ys,Zs,'g');

and get:

enter image description here