Fill up a variable number of rows to match a certain size
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
Voss
on 20 Jul 2022
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
2 Comments
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices 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!