演算処理した結果を配列にします。配列は毎回サイズが異なる。回数はN回とし、これをfor文処理したい。
Afficher commentaires plus anciens
A1=演算処理
A2=演算処理
・
・
An=演算処理
これを
for 1:n
????
end
Réponses (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 commentaires
Atsushi Ueno
le 4 Nov 2021
result = [];
for i = 1:n
eval(['result(end + 1) = A' num2str(i) ';']); % 最近話題の技、こっちの方が速い
end
end + 1 の技については下記のツイートを参考にさせて頂きました。
章 佐々木
le 8 Nov 2021
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!