Indexing for cell arrays

I have 10x1300 cell array z, how do i find a certain value of z using indexing
find(abs(z-z_position)<intvl) did not work
and how do i do the opposite as well? eg. z{1,1}(1)
A portion of z, z value is random for each cell.
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]

 Accepted Answer

cellfun( @(Z) find(abs(Z-z_position)<intvl), z, 'uniform', 0)
the output will be a cell array each element of which is the list of indices for the corresponding cell in z.

9 Comments

Thanks! It works, how do i use it to find the corresponding values in another cell M which is exactly the same size, 10x1300 cell of same size as z. E.g I am finding the minimum of M for z=1,
index=cellfun( @(Z) find(abs(Z-1)<0.005), z, 'uniform', 0);
min(M(index)); < how should i change this part?
cellfun(@(IDX) min(M(IDX)), index, 'uniform', 0)
Thanks!
Hi, i got an error which says Error using min Invalid data type. First argument must be numeric or logical. How do i fix this? Does this have something to do with the zeros?
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]
I have posted another question with regards to this
cellfun(@(m, IDX) min(m(IDX)), M, index, 'uniform', 0)
I got another error :Subscripted assignment dimension mismatch.
I have checked the dimensions, they are both 10x1300 cell arrays. Is it something else I am missing?
Joseph Lee
Joseph Lee on 21 Nov 2017
Edited: Joseph Lee on 21 Nov 2017
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 you need to know just the value out of all of the M, or do you need to know which cell of M it came from and the index inside that cell?
Only the min out of all the M, one single value.

Sign in to comment.

More Answers (0)

Categories

Tags

Community Treasure Hunt

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

Start Hunting!