How to define the location/position of a number in a specific cell array?
조회 수: 1 (최근 30일)
이전 댓글 표시
I have a question about a command in a code.
I have a 82x1 cell array named MY. In this array there is a number equal to "1" in the line 41. I would like to find the location/position of this number in this array (I mean I would like to have as a result the 41 line number). The other elements of this array have punctuations marks "[]" (see image uploaded
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1276675/image.png)
I tried to use:
location=find(table2array(MY{:}) == 1)
but it is no use ( I mean I want to have location=41).
Could you please help me?
댓글 수: 0
채택된 답변
Star Strider
2023년 1월 28일
편집: Star Strider
2023년 1월 29일
It would help to have the actual cell array.
Try something like this —
MY = {[]; []; []; 1; []; []; []}
loc = find(cellfun(@(x)~isempty(x), MY))
EDIT — (29 Jan 2023 at 00:54)
Code revision (improved efficiency).
.
댓글 수: 0
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Cell Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!