how to save result of for loop
1 回表示 (過去 30 日間)
古いコメントを表示
if i have the function
[label,s] = LSC(data,k,opts)
for p =1:100;
r = 3;
.
.
[label,s] = kmedo(U',k);
end
end
if the output s is a matrix n x n every time (where n is the size of data) so how to save all results(s)
0 件のコメント
回答 (1 件)
Wayne King
2016 年 4 月 21 日
編集済み: Wayne King
2016 年 4 月 21 日
Outside the loop allocate a 3D matrix of zeros
Smat = zeros(n,n,p); % p here is the upper bound on the for loop
Then inside the loop assign
Smat(:,:,p) = s;
have your function return Smat.
3 件のコメント
Wayne King
2016 年 4 月 22 日
because your function is returning, s, look at your function definition
[label,s] = LSC(...)
In my original answer, I stated "have your function return Smat"
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!