Recording values from a loop
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I am using a nested for loop to create an index of calculated values. I need it so everytime a value of T is calculated to be reported in order for the first iteration of the loop to the end. In this format:
where beds is the number of loops, n=beds
T1 T2 T3 ... Tn
1 2 3 ... n
Maybe this is really simple but I cannot get it to work, here's what I've tried
(Matlab R2016b)
while
%Calculations
for z=1:beds;
temps(z)=(T);
end
%Misc code
beds=beds+1;
end
returns 126 of the same T value as Tn
this code just run each temps off as the same value in a 1x126 double and this is not intended.
Respuestas (1)
Kevin Phung
el 11 de Feb. de 2019
Editada: Kevin Phung
el 11 de Feb. de 2019
You're missing indexing for your T
while
%Calculations
for z=1:beds;
temps(z)=T(z);
end
%Misc code
beds=beds+1;
end
however.. it looks like youre just setting temps to be equal to T-- do you even need the forloop?
2 comentarios
Kevin Phung
el 11 de Feb. de 2019
Editada: Kevin Phung
el 11 de Feb. de 2019
'NB : I don't think z=beds is required, temps(beds) should work.'
yep, it will save you some space and time, however insignificant. Glad you caught your error.
for future reference though, do try to provide as much information as possible so it'll be easier to answer your question!
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!