Finding rows/indices by comparing individual elements of rows of one matrix to another
1 次查看(过去 30 天)
显示 更早的评论
Let's say I have a
matrix and a
matrix as follows:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/304907/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/304911/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/304915/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/304919/image.png)
I want to find the indices of rows in
such that the row elements are less than the row elements of
: e.g., in the third row, 1<2 and -2<1. I can do this by the following code:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/304923/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/304927/image.png)
[row,col] = find(m1(:,1)<=m2(1,1) & m1(:,2)<=m2(1,2));
The code therefore identifies row 3 and row 4 from
.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/304931/image.png)
My question is: if I had more columns, how could I implement the same action but without using "&" everytime to define the conditions for each column as I did in my code? I am basically asking for a generalized version of what I have done.
I hope I was clear with my question. Thanks in advance!
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!