変数'X'のサイズがループ反復ごとに変更されているようです。高速化する為に事前割り当てを検討してください(高速化)
    23 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
    wataru suzuki
 am 7 Nov. 2020
  
    
    
    
    
    Kommentiert: Ameer Hamza
      
      
 am 8 Nov. 2020
            MATLABで1~変数Nを用いてfor文で配列を作成してました。すると
「変数'X'のサイズがループ反復ごとに変更されているようです。高速化する為に事前割り当てを検討してください」
というようなMATLABのメッセージが発生しました。
for文の繰り返す数が多く、このエラーメッセージのように高速化したいのですが、どのように改善すべきか私では分かりませんでした。
どのようにすべき、考えるか教えていただけないでしょうか?
0 Kommentare
Akzeptierte Antwort
  Ameer Hamza
      
      
 am 7 Nov. 2020
        You need to do pre-allocation. Read here: https://www.mathworks.com/help/matlab/matlab_prog/preallocating-arrays.html
For example, the following code will show the warning.
x = [];
for i = 1:10
    x = [x i];
end
Similarly following code will also show warning
x = [];
for i = 1:10
    x(i) = i;
end
Following code use pre-allocation and you will get no warning
x = zeros(1,10); % pre-allocation
for i = 1:10
    x(i) = i; % no warning now
end
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
				Mehr zu ループと条件付きステートメント finden Sie in Help Center und File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!