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

 채택된 답변

Mohammad Abouali
Mohammad Abouali 2015년 1월 16일
편집: Mohammad Abouali 2015년 1월 16일

0 개 추천

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

Cladio Andrea
Cladio Andrea 2015년 1월 16일
i was exactly looking for this. Thank you Mohammad!!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2015년 1월 16일

1 개 추천

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

Cladio Andrea
Cladio Andrea 2015년 1월 16일
Thanks a lot, In 10 minutes i got 2 perfect answer thank you!!

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by