Can you put a function inside a for loop?
97 ビュー (過去 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!