Borrar filtros
Borrar filtros

Fill matrix with zeros

15 visualizaciones (últimos 30 días)
Cladio Andrea
Cladio Andrea el 16 de En. de 2015
Editada: Mohammad Abouali el 16 de En. de 2015
Hello, i have two matrices, one has fixed size 100x1 and the second one changes lets say could be 97x4 or 103x4, i want to multiply just the first columns of these two, but how can i multiply them, i just want to fill the rest of the rows with zeros if its less than 100 ,and i want to remove the last three columns if it is more than 100, Any ideas? Thank you

Respuesta aceptada

Mohammad Abouali
Mohammad Abouali el 16 de En. de 2015
Editada: Mohammad Abouali el 16 de En. de 2015
A: is the Fixed Sized Matrix
B: is the Variable Sized Matrix
A(:,1) .* [B(1:min(size(A,1),size(B,1)),1); zeros(size(A,1)-size(B,1),1)]
  1 comentario
Cladio Andrea
Cladio Andrea el 16 de En. de 2015
i was exactly looking for this. Thank you Mohammad!!

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 16 de En. de 2015
Try this:
% Sample data
matrix1 = randi(9, 100, 1);
matrix2 = randi(9, 97, 4);
[rows, columns] = size(matrix2)
if rows > 100
% Crop off any rows more than 100
matrix2 = matrix2(1:100, :);
elseif rows < 100
% Pad with rows of zero.
matrix2(100,:) = 0;
end
% Now multiply.
col1Product = matrix1 .* matrix2(:, 1);
  1 comentario
Cladio Andrea
Cladio Andrea el 16 de En. de 2015
Thanks a lot, In 10 minutes i got 2 perfect answer thank you!!

Iniciar sesión para comentar.

Categorías

Más información sobre Matrix Indexing 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!

Translated by