Can I make the matrix of size n with only x elements known and rest all 0?
조회 수: 1 (최근 30일)
이전 댓글 표시
I have a matrix that can have some x known values. But I want to make it of fixed length n. In other words, I want to append 0s and make one n sized matrix from x known elements and n-x 0s.
I think that this can be surely done by just one for loop, but it would be great if there is a way to do this with a one-line command.
댓글 수: 0
채택된 답변
Ameer Hamza
2020년 11월 14일
No for loop is needed. You can use padarray(), but easier is
n = 20;
x = 1:12;
y = [x zeros(1, n-numel(x))]
댓글 수: 0
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!