How to fill the remaining "N" number of rows, of an already populated vector, with zeros
조회 수: 15 (최근 30일)
이전 댓글 표시
It may be confusing, so let me explain. The "GV" data I provided has values in it. It is size (18,001 x 1). I want the to fill the remaining "N" number of rows with zeros. So it may be a (20,000 x 1) or perhaps a (30,000 x 1) vector, but still with the first 18,001 rows filled with the "GV" values. How to do this??
Thank you in advance!
댓글 수: 0
채택된 답변
추가 답변 (2개)
Bruno Luong
2018년 9월 18일
편집: Bruno Luong
2018년 9월 18일
% ... Compute GV
GV(20000)=0 % if you are sure 20000>length(GV), if not protect with IF
dpb
2018년 9월 18일
Alternatively, and perhaps more efficient depending upon how GV is generated/obtained...
GV(Ntotal,1)=0; % preallocate (could also write zeros(Ntotal,1) )
GV(1:N)=GVcalculation(1:N); % put the calculation results in first N locations
Which way is more effective depends on the details we don't know...
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!