Info
この質問は閉じられています。 編集または回答するには再度開いてください。
Someone can help with the matrix manipulation?
4 ビュー (過去 30 日間)
古いコメントを表示
Hello everyone,
I have two matrix A and B and i wanna find the row equals in both matrix and remove the line on matrix B. I wanna safe on the vector the position the lines,How can i do it?
For example:
A = [1 2 6 3;
4 5 6 9;
7 7 7 6;
9 8 7 3];
B = [0 9 6 3;
3 5 1 9;
7 7 7 6;
9 8 9 9];
the row equals is row 3. So i wanna find the rows equal, that's row 3 and leave the matrix B this way:
B = [0 9 6 3;
3 5 1 9;
9 8 9 9];
vector = 3;
I tryed this way:
ix = all(A == B, 2);
B = B(~ix, :)
vector = find(ix)
but i can't use the function all, i can use only the functions: "find", "unique" and "isempty". I can use the function "for" and "size" too.
Ps.: If i put the two matrix with diffent dimensions, my code not working. Appear this error:
"Error using ==
Matrix dimensions must agree."
Help me
2 件のコメント
madhan ravi
2020 年 6 月 1 日
編集済み: madhan ravi
2020 年 6 月 1 日
Does it mean it's your exam/homework?
"Ps.: If i put the two matrix with diffent dimensions, my code not working. Appear this error:"
Was not there another option in your previous question?? https://www.mathworks.com/matlabcentral/answers/539511-somone-can-help-me-with-unique-and-find-function
回答 (1 件)
David Hill
2020 年 6 月 1 日
I assume you can use sum.
vector=[];
for k=1:size(A,1)
for m=1:size(B,1)
if sum(B(m,:)==A(k,:))==size(A,2)
vector=[vector,m];
end
end
end
B(vector,:)=[];
0 件のコメント
この質問は閉じられています。
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!