How to add zeros in front of an array

24 visualizaciones (últimos 30 días)
Gn Gnk
Gn Gnk el 27 de Dic. de 2019
Respondida: Walter Roberson el 27 de Dic. de 2019
Hello ,
i want to add zeros in front of an array but i want to do that for 3 times and each time the zeros are increasing by1 .
eg 1st time : 0 array
2nd time : 00 array
3rd time : 000 array
I want to use a for-loop but i am getting errors like that :
for l=1:3
output(l,:)=[zeros(1,l) , example_array];
end
Any ideas?

Respuesta aceptada

Walter Roberson
Walter Roberson el 27 de Dic. de 2019
output = cell(3,1);
for l=1:3
output{l}=[zeros(1,l) , example_array];
end
The reason what you tried failed is that the rows are all different lengths.
If you wanted to do
0 array 0 0
0 0 array 0
0 0 0 array
then you could do something close to what you had:
L = length(example_array);
output = zeros(3, L+3);
for l = 1 : 3
output(l, l+1:l+L) = example_array;
end

Más respuestas (0)

Categorías

Más información sobre Multidimensional Arrays 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