필터 지우기
필터 지우기

Select rows given a condition

조회 수: 104 (최근 30일)
Maria
Maria 2014년 6월 24일
답변: Reda 2023년 11월 10일
I have a big- cell variable and I want to select it, considering the first row. So for instance if I have
A:
1997 FD 89
1997 GD 65
1999 FDK 87
2010 UY 123
I would like to get
B:
1997 FD 89
1997 GD 65
I tried to use the '==1997' function but it is not working because the input is a cell. An when I use 'isequal' I get B but it's a '0x0 cell' variable. Can anyone help me? Thanks a lot!

채택된 답변

Titus Edelhofer
Titus Edelhofer 2014년 6월 24일
Hi Maria,
you need to convert the first column into a vector
firstColumn = cell2mat(A(:,1));
rows1997 = A(firstColumn==1997, :);
Titus
  댓글 수: 1
Maria
Maria 2014년 6월 24일
Yes! I just tried cell2mat and it worked perfectly! Thank you very much! :)

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

추가 답변 (2개)

aneps
aneps 2014년 6월 24일
편집: aneps 2014년 6월 24일
Try this:
B=A(any(A==1997,2),:)
  댓글 수: 2
Maria
Maria 2014년 6월 24일
Hey. It gives me exactly the same error!
'Undefined function 'eq' for input arguments of type 'cell'
:(
Maria
Maria 2014년 6월 24일
Still the same problem! I cannot use '==', it's always giving an error!

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


Reda
Reda 2023년 11월 10일
Dear sir,
I have a file name(metadat) which have 3 column and no of rows. My question is how to select all rows from the file with specific condition such as PP=0. I try allot of salutions but i didnt get the wright one. Thanks alot

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by