MATLAB Answers

0

Why is the size of the function different in plot3 and quiver3?

Asked by physics scientist on 20 Sep 2017
Latest activity Commented on by Chad Greene
on 20 Sep 2017
f = 10^8;
x = 0:0.1:5;
c=3*10^8;
z =sin(2*pi*x*f/c+f*x/c);
y =sin(2*pi*x*f/c+f*x/c+pi/2);
o = zeros(size(x));
quiver3(x,o,o,o,z,o,'LineStyle','--');
hold on
quiver3(x,o,o,o,o,y,'LineStyle','--')
hold on
quiver3(x,o,o,o,z,y,'LineStyle','-')
hold on
plot3(x,z,o)
hold on
plot3(x,o,y)
hold on
plot3(x,z,y)
axis square

output:

  0 Comments

Log in to comment.

1 Answer

Answer by Chad Greene
on 20 Sep 2017
Edited by Chad Greene
on 20 Sep 2017
 Accepted Answer

The quiver and quiver3 functions automatically scale the vectors. To turn off automatic scaling, add a 0 just before setting the 'LineStyle'. That is,

quiver3(x,o,o,o,z,o,0,'LineStyle','--');
hold on
quiver3(x,o,o,o,o,y,0,'LineStyle','--')
quiver3(x,o,o,o,z,y,0,'LineStyle','-') 

  3 Comments

Also a small note: You only need to say hold on once, and the hold will stay on for that plot until you say hold off.

Thank you! I have one more problem the all the axes are in different scales i.e. lets say z axis shows 2 units while y axis shows 6 units so they should be shown equal in length on screen but here they are equal, is there any way to show them with the size proportional to their values?

You can set the relative aspect ratio of a plot with daspect. To make x, y, and z axes all equal just do

daspect([1 1 1]) 

Log in to comment.


Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today