필터 지우기
필터 지우기

How do I extract a row of data from a cell array?

조회 수: 44 (최근 30일)
Brad
Brad 2014년 5월 7일
댓글: Bryan 2018년 10월 2일
I have a 3 x 4 cell array, (a), that looks like this;
'Due' 55000 1 100
'WFR' 55100 2 200
'Due' 55200 20 300
where column 1 is of char, and the others are doubles.
I'm attempting to extract the rows of data based on the values in the 3rd column being greater than 2 (20 in this case).
Desired output is cell b = 'Due' 55200 20 300
I'm using the following code;
b=a(~ismember(a(:, 3), [1 2]), :);
I keep getting the following error message;
"Input A of class cell and input B of class double must be cell arrays of strings, unless one is a string"
This is the first time I've attempted to extract rows of data from cell arrays. Am I doing something wrong? If so, how do I approach this problem in order to get b?

채택된 답변

Andrei Bobrov
Andrei Bobrov 2014년 5월 7일
b = a(cat(1,a{:,3}) > 2,:)
  댓글 수: 3
fei peng
fei peng 2016년 10월 19일
GOOD
Bryan
Bryan 2018년 10월 2일
Excellent! Thanks

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

추가 답변 (1개)

Sara
Sara 2014년 5월 7일
If you know which row you want to extract, you can do:
b = a(row,:);
  댓글 수: 1
Brad
Brad 2014년 5월 7일
Sara, I'm looking to extract the row based on a specific value in the 3rd column (which varies). I did try your approach and it works. But I need some ideas on how to approach this when the values in the 3rd column are not equal to 1 or 2. Thanks.

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

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by