フィルターのクリア

How to successively fill a vector with for loop?

25 ビュー (過去 30 日間)
Daniel Gray
Daniel Gray 2018 年 2 月 4 日
編集済み: Stephen23 2018 年 2 月 4 日
I have my code set up as follows:
thmaxn = [];
for ang=[0, pi/2, pi, 3*pi/2, 2*pi]
thmax = phasedist(ang,N,rhoss);
end
Don't worry what the function does, it just gives a value for each angle. I just wondered how I could put each value into the thmaxn vector successively?
Thanks

採用された回答

Stephen23
Stephen23 2018 年 2 月 4 日
編集済み: Stephen23 2018 年 2 月 4 日
Preallocate the output array and then simply use indexing:
ang = 0:pi/2:2*pi;
thmax = zeros(1,numel(ang));
for k = 1:numel(ang)
thmax(k) = phasedist(ang(k),N,rhoss);
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by