演算処理した結果を配列にします。配列は毎回サイズが異なる。回数はN回とし、これをfor文処理したい。
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
A1=演算処理
A2=演算処理
・
・
An=演算処理
これを
for 1:n
????
end
0 commentaires
Réponses (1)
Atsushi Ueno
le 4 Nov 2021
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 の技については下記のツイートを参考にさせて頂きました。
Voir également
Catégories
En savoir plus sur ループと条件付きステートメント dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!