plotting in a for loop

1 vue (au cours des 30 derniers jours)
Christopher
Christopher le 3 Juin 2013
Hello, I am trying to plot in a while loop and I am having trouble figuring out how to set this up. I am calling a function that I have written to vary the x component of the vector from -20 to 20 in increments of 5. The code for the function and the file I am using are shown below.
Code:
x1=-1;
y1=0;
z1=0;
x2=1;
y2=0;
z2=0;
x=-25;
y=5;
z=0;
while x<20
x=x+5
vortexsegment(x1,y1,z1,x2,y2,z2,x,y,z);
end
Function:
function[Vx,Vy,Vz]=vortexsegment(x1,y1,z1,x2,y2,z2,x,y,z);
S=[x1,y1,z1]; % defining points for start
E=[x2,y2,z2]; % defining points for end
R=[x,y,z]; % defining points for point of interst
A=S-R; % Finding vector a
B=E-R; % Finding vector b
Z1=cross(A,B);
Z2=dot(A,B);
MagA=norm(A);
MagB=norm(B);
q=(Z1./(dot(Z1,Z1))).*(MagA+MagB).*(1-(Z2./(MagA.*MagB)));
V=(1./(4.*3.14)).*q
Vx=V(1,1)
Vy=V(1,2)
Vz=V(1,3)
Thanks

Réponse acceptée

Image Analyst
Image Analyst le 3 Juin 2013
Did you try to plot Vx?
while x < 20
x=x+5
[Vx, Vy, Vz] = vortexsegment(x1,y1,z1,x2,y2,z2,x,y,z);
plot(Vx, 'b-', 'LineWidth', 3);
grid on;
drawnow;
end
  2 commentaires
Christopher
Christopher le 3 Juin 2013
That seems to do the trick. Thank you! What is it called when you use [Vx, Vy, Vz] = vortexsegment(x1,y1...etc)? I haven't seen that before? I am still somewhat of a newb with matlab.
Thanks again
Image Analyst
Image Analyst le 3 Juin 2013
That's called accepting the return arguments into variables in the calling routine, or something like that. vortexsegment() calculates them and sends them back to the caller, but unless the calling routine accepts them into variables, they are thrown away.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by