# How to define the location/position of a number in a specific cell array?

3 ビュー (過去 30 日間)
Ivan Mich 2023 年 1 月 28 日

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
I tried to use:
location=find(table2array(MY{:}) == 1)
but it is no use ( I mean I want to have location=41).

サインインしてコメントする。

### 採用された回答

Star Strider 2023 年 1 月 28 日

It would help to have the actual cell array.
Try something like this —
MY = {[]; []; []; 1; []; []; []}
MY = 7×1 cell array
{0×0 double} {0×0 double} {0×0 double} {[ 1]} {0×0 double} {0×0 double} {0×0 double}
loc = find(cellfun(@(x)~isempty(x), MY))
loc = 4
EDIT — (29 Jan 2023 at 00:54)
Code revision (improved efficiency).
.

サインインしてコメントする。

### その他の回答 (1 件)

Voss 2023 年 1 月 28 日
idx = find(cellfun(@(x)isequal(x,1),MY));

サインインしてコメントする。

### カテゴリ

Find more on Cell Arrays in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by