plotting in a for loop
조회 수: 2 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
Image Analyst
2013년 6월 3일
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
Image Analyst
2013년 6월 3일
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!