Can you put a function inside a for loop?
34 次查看(过去 30 天)
显示 更早的评论
I have this function:
%Outputs
%u - real number - horizontal velocity component due to doublet in global FoR
%v - real number - vertical velocity component due to doublet in global FoR % %Inputs
%p - 1 x 2 array - coordinates [x,z] of point at which to evaluate u,v
%p1 - 1 x 2 array - coordinates [x1,z1] of panel start point
%p2 - 1 x 2 array - coordinates [x2,z2] of panel end point %mu - real number - doublet strength
function [u,v]=cdoublet(p,p1,p2)
Can i put this function inside a for loop to get an array of u and another array for v? Of course, p, p1, p2 will also change for every iteration of the loop. Is it possible to put the function inside the loop?
0 个评论
回答(2 个)
Mischa Kim
2014-3-28
编辑:Mischa Kim
2014-3-28
Sure, e.g.,
a = [5 4 3 2];
for ii = 1:numel(a)
b(ii) = times(a(ii),ii);
end
You can have any other function instead of times inside the loop.
0 个评论
Salaheddin Hosseinzadeh
2014-3-28
Hi Jacob
You have to make anoher function or script, lets call it 'main' in case you made a function, and in 'main' you can call 'cdoublet' and get its outputs, store them in an array and also change the values of p p1... in the main function.
But I suggest ou not to make a function, just write another script and put cdoblet ina for loop
x=[];
y=[];
for i=1:10
p1=i;
p2=i+1; % or what ever
[x(i),y(i)]=cdoublet(p,p1,p2);
end
you can do this in a new sript file
Good Luck!
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!