Error with indexing 'First argument must be numeric or logical'

1 回表示 (過去 30 日間)
Joseph Lee
Joseph Lee 2017 年 11 月 20 日
コメント済み: Joseph Lee 2017 年 11 月 21 日
M & z are both 10x1300 cell arrays of same size
Columns 1296 through 1300
[1×23 double] [1×23 double] [1×29 double] [1×23 double] [1×25 double]
[1×27 double] [1×25 double] [1×25 double] [1×25 double] [1×27 double]
[1×21 double] [1×25 double] [1×27 double] [1×27 double] [1×25 double]
[1×27 double] [1×29 double] [1×29 double] [1×25 double] [1×23 double]
[1×27 double] [1×25 double] [1×23 double] [1×27 double] [1×27 double]
[1×27 double] [1×27 double] [1×23 double] [1×21 double] [1×23 double]
[1×25 double] [1×29 double] [1×27 double] [1×27 double] [1×27 double]
[1×27 double] [1×21 double] [1×21 double] [1×29 double] [1×27 double]
[1×25 double] [1×25 double] [1×25 double] [1×21 double] [1×27 double]
[1×23 double] [1×25 double] [1×25 double] [1×25 double] [1×23 double]
index=cellfun( @(Z) find(abs(Z-1)<0.005), z, 'uniform', 0);
index results Columns 1297 through 1300
[1×0 double] [1×0 double] [1×0 double] [1×0 double]
[1×0 double] [1×0 double] [1×0 double] [1×0 double]
[ 25] [1×2 double] [1×2 double] [1×2 double]
[1×2 double] [1×2 double] [1×2 double] [1×2 double]
[1×2 double] [1×2 double] [1×2 double] [1×2 double]
[1×0 double] [1×0 double] [1×2 double] [1×2 double]
[1×0 double] [1×0 double] [1×0 double] [1×0 double]
[1×0 double] [1×0 double] [1×0 double] [1×0 double]
[1×0 double] [1×0 double] [1×0 double] [1×0 double]
[1×0 double] [1×0 double] [1×0 double] [1×0 double]
Result=cellfun(@(IDX) min(M(IDX)), index, 'uniform', 0); < error occurs on this line finding minimum of M at z=1, how do i fix this?
Is it because of the zeros in index?
  1 件のコメント
Joseph Lee
Joseph Lee 2017 年 11 月 21 日
cellfun(@(m, IDX) min(m(IDX)), M, index, 'uniform', 0)
Tried this code but got another error: Subscripted assignment dimension mismatch.

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

採用された回答

Andrei Bobrov
Andrei Bobrov 2017 年 11 月 21 日
Result = zeros(size(index));
t = ~cellfun(@isempty,index);
Result(t) = cellfun(@(mm,ii)min(mm(ii)),M(t),index(t));
  2 件のコメント
Joseph Lee
Joseph Lee 2017 年 11 月 21 日
編集済み: Joseph Lee 2017 年 11 月 21 日
I got the same error:Subscripted assignment dimension mismatch.
I think i know why, the minimum im looking for is not for each cell array but for all the cells, the result should give only one single value which i am storing into a matrix while increasing the find(abs(Z-1)<0.005) to find(abs(Z-2)<0.005) and so on
Do i just add min?
Result(t) = min(cellfun(@(mm,ii)min(mm(ii)),M(t),index(t)));
Joseph Lee
Joseph Lee 2017 年 11 月 21 日
This does not seem to work. I will open another question to be more specific

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by