How to save variables generated inside 'for' loop which contains a function, to the workspace?

1 vue (au cours des 30 derniers jours)
Bhaswar Dutta Gupta
Bhaswar Dutta Gupta le 2 Sep 2018
Rouvert : Walter Roberson le 22 Déc 2018
I have a long code, part of which involves calling a function inside a 'for' loop. Please see code below:
zz = linspace(0,0.2,length);
for qq=1:1:length(zz)
% some stuff %
[Z, AT, AW, W] = myfunc(zz(qq));
A = AT(end,:);
end
'myfunc' is written as a separate .m file. The problem is the variable 'A' or any of the variables returned from the function is not available outside this loop. What can I do save these variables so that I can use them in the next steps of my code?
  10 commentaires
Walter Roberson
Walter Roberson le 2 Sep 2018
Your loop starts at 2. What happens if length(zz) is 1 ?
Be careful with length(), as it will report 0 if any dimension is empty, and will return the largest dimension otherwise, not a particular dimension.
Bhaswar Dutta Gupta
Bhaswar Dutta Gupta le 2 Sep 2018
In my original question:
zz=linspace(0,0.2,Length);
I am starting from qq=2 as qq=1 has value 0, and that is not needed in my calculation.

Connectez-vous pour commenter.

Réponses (1)

ahmed nebli
ahmed nebli le 2 Sep 2018
u can create an array, and use the function vertcat to store the variable A each time

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits


Version

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by