Filter löschen
Filter löschen

plotting in a for loop

1 Ansicht (letzte 30 Tage)
Christopher
Christopher am 3 Jun. 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

Akzeptierte Antwort

Image Analyst
Image Analyst am 3 Jun. 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 Kommentare
Christopher
Christopher am 3 Jun. 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 am 3 Jun. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by