How to store all outputs from this nested for loop
2 ビュー (過去 30 日間)
古いコメントを表示
I have this for loop which goes through 3 different variables. I need to record all outputs so that I can plot the 3 variables and the outputs as a 3D colour surface plot similar to the second plot here https://www.mathworks.com/help/matlab/ref/surf.html
At the moment it only gives the last output so if someone can point me in the right direction to gettiing all outputs.
for s=0:9 % Variable 1
for om=0.1:0.1:1 % Variable 2
for mu=0.1:0.1:1 % Variable 3
nll = mylikelihood(s,om,mu); % This is a function I made.
end
end
end
Also if anyone could see how I can vectorise the code so that it runs faster that would be appreciated.
2 件のコメント
Walter Roberson
2021 年 7 月 9 日
That code cannot be vectorized unless your function can be vectorized, but you did not show the code for your function so we do not know what can be done with it.
採用された回答
Stephen23
2021 年 7 月 9 日
Vs = 0:9; % Variable 1
Vom = 0.1:0.1:1; % Variable 2
Vmu = 0.1:0.1:1; % Variable 3
Ns = numel(Vs);
Nom = numel(Vom);
Nmu = numel(Vmu);
nll = nan(Ns,Nom,Nmu);
for k1 = 1:Ns
for k2 = 1:Nom
for k3 = 1:Nmu
nll(k1,k2,k3) = mylikelihood(Vs(k1),Vom(k2),Vmu(k3));
end
end
end
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Graphics Performance についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!