help with preallocating matrix ?

1 visualización (últimos 30 días)
Rahim Rahim
Rahim Rahim el 7 de Feb. de 2021
Comentada: Rahim Rahim el 7 de Feb. de 2021
I want to preallocate a matrix a dynamic matrix Archive[M,6], The size of our matrix limited by 200. At beggening M=1 then add elements to Archive by using the following function:
function Add ( Archive, Solution)
while( size(Archive,1) <= 200 )
Archive=[Archive;Solution]
end
end
where solution is Solution[1,6].
How preallocate the Archive matrix ?

Respuestas (1)

KALYAN ACHARJYA
KALYAN ACHARJYA el 7 de Feb. de 2021
If it is are fixed,can consider the extra zeros (If generated data are not sufficients to allocate all)
Archive=zeros(1,200);
Without knowing the size of the data? you may do following way
Archive=[];
Still it not perfect as preallocate with specific size. More, check with the Elapsed time, to see the time difference of execution.
  1 comentario
Rahim Rahim
Rahim Rahim el 7 de Feb. de 2021
@KALYAN ACHARJYA thank you for answer, but I won't zeros
Are there another methods ? because I wille added [0,0,0,0,0,0,,0] as a soulution so I dont want to use this method.

Iniciar sesión para comentar.

Categorías

Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by