How to add zeros in front of an array
10 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Gn Gnk
il 27 Dic 2019
Risposto: Walter Roberson
il 27 Dic 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?
0 Commenti
Risposta accettata
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
0 Commenti
Più risposte (0)
Vedere anche
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!