Filling matrix with zeros whilst retaining original value

1 view (last 30 days)
Hi
I got a 1x14 matrix filled with random numbers. I want the remaining entires to be filled with zero so that I get a 1x180 matrix whils the original 14 values are kept.
thanks

Accepted Answer

Bjorn Gustavsson
Bjorn Gustavsson on 22 Aug 2020
Something like this?
a = randn(1,14);
a(end+1:180) = 0;
HTH
  2 Comments
Walter Roberson
Walter Roberson on 22 Aug 2020
a = randn(1,14);
a(180) = 0;
Everything between 15 and 179 will be filled with the default value 0.
Bjorn Gustavsson
Bjorn Gustavsson on 23 Aug 2020
...and Walter's solution is "about a factor of 2 faster" for growing the array to 1 x 180, my solution adapts to other values, use either.

Sign in to comment.

More Answers (0)

Categories

Find more on Line Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!