How to add zeros in front of an array

23 次查看(过去 30 天)
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?

采纳的回答

Walter Roberson
Walter Roberson 2019-12-27
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 个)

类别

Help CenterFile Exchange 中查找有关 Multidimensional Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by