Find the rows with specific value for each column

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!

Respuestas (2)

madhan ravi
madhan ravi el 24 de Oct. de 2018
Editada: madhan ravi el 24 de Oct. de 2018
a=randi([1 10],4,10)
[row,col]=find(ismember(a,10));
col %represents in which column the value is

7 comentarios

heidi pham
heidi pham el 24 de Oct. de 2018
Thank you! If I understand your answer correctly, it seems that you are finding the column which has value 1.2, in the first row?
I actually want to find for each column, the row that has a specific value (like 1.2 for instance).
Sorry if i misunderstood your point.
madhan ravi
madhan ravi el 24 de Oct. de 2018
Editada: madhan ravi el 24 de Oct. de 2018
No you will get which columns has that value and instead of 1 if you use the iterator for instance i which goes from 1 to 37( meaning row numbers in this case) you will be able to find columns having the value
heidi pham
heidi pham el 24 de Oct. de 2018
Thanks, it works if I want to get which column, but actually I want to know which rows that has a certain value for each column. So I will need to do iteration for 1 million times, and it is quite tedious...
madhan ravi
madhan ravi el 24 de Oct. de 2018
Or use ismember()
madhan ravi
madhan ravi el 24 de Oct. de 2018
See the edited answer now , you can get rid of loops and ismember is more efficient
heidi pham
heidi pham el 24 de Oct. de 2018
thanks, i will check it!
madhan ravi
madhan ravi el 24 de Oct. de 2018
Sure thing!

Iniciar sesión para comentar.

Akira Agata
Akira Agata el 24 de Oct. de 2018
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

Categorías

Preguntada:

el 24 de Oct. de 2018

Comentada:

el 24 de Oct. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by