How to store all outputs from this nested for loop
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Leo Tu
el 9 de Jul. de 2021
Comentada: Leo Tu
el 9 de Jul. de 2021
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 comentarios
Walter Roberson
el 9 de Jul. de 2021
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.
Respuesta aceptada
Stephen23
el 9 de Jul. de 2021
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
Más respuestas (0)
Ver también
Categorías
Más información sobre Graphics Performance en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!