Clear Filters
Clear Filters

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

1 view (last 30 days)
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 Comment
Joseph Lee
Joseph Lee on 21 Nov 2017
cellfun(@(m, IDX) min(m(IDX)), M, index, 'uniform', 0)
Tried this code but got another error: Subscripted assignment dimension mismatch.

Sign in to comment.

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 21 Nov 2017
Result = zeros(size(index));
t = ~cellfun(@isempty,index);
Result(t) = cellfun(@(mm,ii)min(mm(ii)),M(t),index(t));
  2 Comments
Joseph Lee
Joseph Lee on 21 Nov 2017
Edited: Joseph Lee on 21 Nov 2017
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 on 21 Nov 2017
This does not seem to work. I will open another question to be more specific

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!