필터 지우기
필터 지우기

How to use find function to find input of 'cell' type?

조회 수: 4 (최근 30일)
C Zeng
C Zeng 2015년 4월 15일
편집: Image Analyst 2015년 4월 16일
Hello, I have 'raw' as an array of all cells read from excel (number or non-number). I would like to find the row numbers where the cell is 'ABC', and return the first row.
When I use 'find' function it returns an error:
>>find(raw, 'ABC','first')
Undefined function 'find' for input arguments of type 'cell'.
Is there a way to find the row for a cell content in Matlab? If so, how can I find the row of both that one vector having some cell, and another vector having another cell?
  댓글 수: 4
Image Analyst
Image Analyst 2015년 4월 15일
No it's not. But see if my answer below is okay.
C Zeng
C Zeng 2015년 4월 15일
Thanks!

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

채택된 답변

Image Analyst
Image Analyst 2015년 4월 15일
ca = {'abc', 'def';
'abcx', 'row 2';
'yy', 'row 2 abc';
'zzzz', 'abc';
'abc', 'line 3'}
[ia, ib] = ismember(ca, 'abc')
firstRow = find(ia(:, 1), 1, 'first')
In the command window:
ca =
'abc' 'def'
'abcx' 'row 2'
'yy' 'row 2 abc'
'zzzz' 'abc'
'abc' 'line 3'
ia =
1 0
0 0
0 0
0 1
1 0
ib =
1 0
0 0
0 0
0 1
1 0
firstRow =
1
  댓글 수: 2
C Zeng
C Zeng 2015년 4월 15일
편집: C Zeng 2015년 4월 15일
What if I want to find out which row return number j (j changes in the loop), where the column vector is of cells.
if I input: ismember(list, 'j'); it returns an error: Input A of class cell and input B of class cell must be cell arrays of strings, unless one is a string.
Thanks!
Image Analyst
Image Analyst 2015년 4월 16일
편집: Image Analyst 2015년 4월 16일
Please create a cell array like I did so I can work on it. And tell me which row and column you want to find/detect and return to your program.

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by