How to save variables generated inside 'for' loop which contains a function, to the workspace?
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
Walter Roberson
2018-9-2
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.
回答(1 个)
ahmed nebli
2018-9-2
u can create an array, and use the function vertcat to store the variable A each time
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!