The Variable appears to change size on every loop iteration
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
pooja
el 19 de Mzo. de 2014
Comentada: Mahmoud Emad
el 8 de Abr. de 2020
[num_class,num_instance]=size(Outputs);
temp_Outputs=[];
temp_test_target=[];
for i=1:num_instance
temp=test_target(:,i);
if((sum(temp)~=num_class)&&(sum(temp)~=-num_class))
*temp_Outputs=[temp_Outputs,Outputs(:,i)];
temp_test_target=[temp_test_target,temp];*
end
end
Error: The Variable "temp_Outputs" appears to change size on every loop iteration
Question : I have No clue how to Preallocate it ?? Please help !!
0 comentarios
Respuesta aceptada
per isakson
el 19 de Mzo. de 2014
Editada: per isakson
el 19 de Mzo. de 2014
This is not an error, it's a warning. It is inefficient to change size of a variable in a loop.
However, the if-statement makes it difficult to know the final size in advance, which is "needed" to preallocate.
IMO: don't care about the warning if the execution time is ok. It is possible to suppress it.
See:
3 comentarios
per isakson
el 19 de Mzo. de 2014
Editada: per isakson
el 19 de Mzo. de 2014
Check the links I provided. They are in the order from basic to advanced. There is no single sentence answer.
Mahmoud Emad
el 8 de Abr. de 2020
What if I had an execution time problem with a code very similar to this, my vector also is created by conactenation in a for loop, is there an efficient alternative ?
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements 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!