How to find common elements in each row of two different matrices?the output must be an array whose rows are made up with the element in common of each row of the matrices in input

조회 수: 3 (최근 30일)
Sorry I am a very beginner in Matlab but I hope someone could explain me where I made a mistake and how I could get the output requested. Thank you Matrix A 363×1226 Matrix B 363x1226 Qq=1:363 For C(qq,:) =intersect(A(qq,:), B(qq, :) ; End
  댓글 수: 2
Ilian
Ilian 2020년 4월 7일
It's not entirely clear to me how you want C to look. The number of rows should of course be the same, but what about the length of the rows? I assume the number of common elements will vary between rows. Depending on what you want, cells could be te solution:
A = [1 2 3; 4 5 6; 7 8 9; 10 11 12];
B = [3 2 4; 4 4 6; 6 7 8; 13 14 15];
C = cell(3,1);
for i = 1:size(A,1)
C{i} = intersect(A(i,:),B(i,:));
end
If this is not what you're looking for, please try to be more specific.
Camilla Ancona
Camilla Ancona 2020년 4월 17일
Thank you very much for helping me. Yes the length of each row can vary depending on the number of the elements in common.

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

채택된 답변

SaiDileep Kola
SaiDileep Kola 2020년 4월 9일
Yes, the above provided example should give some insight in to getting your output
for further study refer to link, to learn accessing matrices

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by