want to use output matrix obtained for every iteration of a for loop in another for loop.
2 次查看(过去 30 天)
显示 更早的评论
hi, i am developing a code where i have 2 functions: the first function gives me a smaller matrix 'k'.
i want to obtain this 'k' matrix for every iteration.
then i want to add these smaller matrices into a larger one, for that i am using the second for loop.
can anyone please guide me on how i can save each 'k' matrix after every iteration, and then use the 'k' matrices and add them to a larger matrix 'K'?
采纳的回答
the cyclist
2024-4-14
Here are two possibilities:
% Save into cell arrays
nsmall = 4;
mcell = cell(nsmall,1);
for k = 1:nsmall
mcell{k} = rand(3); % Note curly brackets, to save as *contents* of the cell
end
% Save each matrix as a "slice" of a three-dimensional array
nsmall = 4;
m3d = zeros(3,3,nsmall);
for k = 1:nsmall
m3d(:,:,k) = rand(3); % Saving each slike
end
更多回答(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!