複素数の事前割り当て
21 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
osamu
am 8 Apr. 2024
Kommentiert: Dyuman Joshi
am 9 Apr. 2024
サイズが大きく、for文などでサイズが変動する配列の扱いについてはzerosなどを使って事前割り当てを行うことが以下のリンクで推奨されています。
これについて対象が複素数の場合はどのような事前割り当てをしたらいいでしょうか?
例えば以下のような式の場合zerosで定義したxに複素数を導入する方法は、目的の事前割り当ての効果を得られているのでしょうか。
x = zeros(1,1000000);
for k = 2:1000000
Real = k*5
Img = k*8
x(k) = complex(Real, Img)
end
0 Kommentare
Akzeptierte Antwort
Dyuman Joshi
am 8 Apr. 2024
You can use this syntax of zeros() to preallocate the data as a complex array -https://in.mathworks.com/help/matlab/ref/zeros.html#d126e1907954
N = 1e5;
%syntax
x = zeros(1, N, 'like', 1i);
for k = 2:N
Real = k*5;
Img = k*8;
x(k) = complex(Real, Img);
end
x(2:5)
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!