Find the rows with specific value for each column

조회 수: 4 (최근 30일)
heidi pham
heidi pham 2018년 10월 24일
댓글: madhan ravi 2018년 10월 24일
Hello, I have a 37*10000 matrix, called matrix A.
For each column, I want to get the rows which has a certain value, let's say, 1.
I know how to do with a certain column, by using find, like: find(any(A(:,1)==1,2)). But here, I need to find such rows for all columns, and the number of column is huge. So I dont know how to deal with it?
And is there any way to deal with it without using loop, since the number of column is huge, I am afraid that using loop might take a lot of time to run the command.
Thanks a lot!

답변 (2개)

madhan ravi
madhan ravi 2018년 10월 24일
편집: madhan ravi 2018년 10월 24일
a=randi([1 10],4,10)
[row,col]=find(ismember(a,10));
col %represents in which column the value is
  댓글 수: 7
heidi pham
heidi pham 2018년 10월 24일
thanks, i will check it!
madhan ravi
madhan ravi 2018년 10월 24일
Sure thing!

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


Akira Agata
Akira Agata 2018년 10월 24일
Another possible solution.
A = randi([1 10],4,10);
idx = any(A == 1); % Represents column index in which the value 1 is
col = find(idx); % Represents column number in which the value 1 is

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by