필터 지우기
필터 지우기

find the row and column value of a specific value in cell array

조회 수: 38 (최근 30일)
Elysi Cochin
Elysi Cochin 2021년 4월 13일
댓글: Rik 2021년 4월 13일
i have a cell array with values
cellarr = {'a','b','c',3,5;'b',5,'a',[],[];'a','c',3,'a',4;'b','a','c','c',3};
i wanted to find the location where a particular number or string occurs
for example i want to get the location where the number = 3
so my expected output is
1st row 3rd column
3rd row 3rd column
4th row 5th column
[row,col] = find(___)
i want both the row and column position as it comes for find function
find not working with cell array
  댓글 수: 3
Elysi Cochin
Elysi Cochin 2021년 4월 13일
i tired that but not getting the row and column value
Xingwang Yong
Xingwang Yong 2021년 4월 13일
After using find(), you just need to convert the linear index into row and col index, see ind2sub

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

채택된 답변

Rik
Rik 2021년 4월 13일
You need to use a bit of trickery to use find (ismember will not work normally either).
cellarr = {...
'a','b','c', 3 ,5;...
'b', 5 ,'a',[] ,[];...
'a','c', 3 ,'a',4;...
'b','a','c','c',3};
val=3;
[row,col] = find(cellfun(@(x) isequal(val,x),cellarr));
[row,col]
ans = 3×2
3 3 1 4 4 5
  댓글 수: 2
Elysi Cochin
Elysi Cochin 2021년 4월 13일
편집: Elysi Cochin 2021년 4월 13일
is it possible to get in order?
row col
1 4
3 3
4 5
or sort based on row
Rik
Rik 2021년 4월 13일
This is the default order for find, but you can use sort (and its second output) to sort on row instead of column.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by