how to declare array of variable size

26 visualizaciones (últimos 30 días)
Mohammad Golam Kibria
Mohammad Golam Kibria el 28 de Abr. de 2011
Hi,
I need an array of variable size. for example
for i: 1:63 myArray(i) = zeros(a,b); end
where a,b are changing its value in every loop;
can any one suggest me how to declare that type of array.

Respuesta aceptada

Oleg Komarov
Oleg Komarov el 28 de Abr. de 2011
for i = 1:63
myArray{i} = zeros(a,b);
end
  2 comentarios
Mohammad Golam Kibria
Mohammad Golam Kibria el 28 de Abr. de 2011
It works but gives a warning. How to remove that warning. warning as follows :
The variable appears to be changed size on every loop iteration. consider preallocating for speed.
Oleg Komarov
Oleg Komarov el 28 de Abr. de 2011
Preallocate before the loop:
myArray = cell(61,1);

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Operators and Elementary Operations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by