Filling matrix with zeros whilst retaining original value

조회 수: 1 (최근 30일)
AA
AA 2020년 8월 22일
댓글: Bjorn Gustavsson 2020년 8월 23일
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

채택된 답변

Bjorn Gustavsson
Bjorn Gustavsson 2020년 8월 22일
Something like this?
a = randn(1,14);
a(end+1:180) = 0;
HTH
  댓글 수: 2
Walter Roberson
Walter Roberson 2020년 8월 22일
a = randn(1,14);
a(180) = 0;
Everything between 15 and 179 will be filled with the default value 0.
Bjorn Gustavsson
Bjorn Gustavsson 2020년 8월 23일
...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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by