How to successively fill a vector with for loop?

76 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by