Can you put a function inside a for loop?
26 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (2)
Mischa Kim
le 28 Mar 2014
Modifié(e) : Mischa Kim
le 28 Mar 2014
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 commentaires
Salaheddin Hosseinzadeh
le 28 Mar 2014
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 commentaires
Voir également
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!