演算処理した結果を配列にします。配列は毎回サイズが異なる。回数はN回とし、これをfor文処理したい。
显示 更早的评论
回答(1 个)
n = 5;
A1 = 1 + 2; % = 3
A2 = 3 + 4; % = 7
A3 = 5 + 6; % = 11
A4 = 7 + 8; % = 15
A5 = 9 + 10;% = 19
result = [];
for i = 1:n
eval(['result = [result A' num2str(i) '];']);
end
result
2 个评论
Atsushi Ueno
2021-11-4
result = [];
for i = 1:n
eval(['result(end + 1) = A' num2str(i) ';']); % 最近話題の技、こっちの方が速い
end
end + 1 の技については下記のツイートを参考にさせて頂きました。
章 佐々木
2021-11-8
类别
在 帮助中心 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!