How to add zeros in front of an array

10 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Walter Roberson
Walter Roberson il 27 Dic 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

Più risposte (0)

Categorie

Scopri di più su Multidimensional Arrays in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by