Fill up a variable number of rows to match a certain size
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Irene Fernandez Ugidos
el 20 de Jul. de 2022
Comentada: Voss
el 20 de Jul. de 2022
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 comentarios
Respuesta aceptada
Voss
el 20 de Jul. de 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrices and Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!