How to record result in a for loop nested in a for loop?
1 次查看(过去 30 天)
显示 更早的评论
The purpose of my code is to combine the output from multiple output which is nested in a for loop.
When i tried (as much as I know), the error "Subscripted assignment dimension mismatch" pops out.
example of the code is as follows:
for i = 1:5
for j = 1:10
matA = [j+i];
matB = [j*5 j+1];
outtemp (j,:) = [matA matB];
end
alpha = i*10;
outfinal (alpha,:) = [outtemp];
end
Thanks in advance.
PS: I tried changing the outfinal into outfinal(i,:), but the same error pops out.
0 个评论
采纳的回答
Cameron B
2020-3-1
Not sure what the point of alpha is, but here’s something to save your data.
clc
clear
for i = 1:5
for j = 1:10
matA = [j+i];
matB = [j*5 j+1];
outtemp (j,:) = [matA matB];
end
alpha = i*10;
outfinal (:,:,i) = [outtemp];
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!