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

1 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by