Fill up a variable number of rows to match a certain size
조회 수: 4 (최근 30일)
이전 댓글 표시
Hi,
I'm running a code of image analysis in which I get a matrix called "Results" that is suposed to be 200x1. Sometimes, instead of 200x1, the Results matrix is smaller, such as 191x1, or 194x1, depending on the original image.
I'd like to concatenate all the Results matrices from every image in one matrix called ResultsGathered, but since they have different sizes, Matlab does not allow me.
How can I make the code to fill up automatically the shorter matrices with 0 to match 200x1?
Thank you
댓글 수: 0
채택된 답변
Voss
2022년 7월 20일
Results = rand(194,1); % a random 194-by-1 vector
disp(Results(end-1:end)); % show the last two elements
% extend with zeros to length 200 if it's smaller than 200
if size(Results,1) < 200
Results(200,1) = 0;
end
disp(Results(end-7:end)); % show the last 8 elements
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!