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]

 채택된 답변

Walter Roberson
Walter Roberson 2017년 11월 20일

1 개 추천

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

Joseph Lee
Joseph Lee 2017년 11월 20일
편집: Joseph Lee 2017년 11월 20일
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)
Joseph Lee
Joseph Lee 2017년 11월 20일
Thanks!
Joseph Lee
Joseph Lee 2017년 11월 20일
편집: Joseph Lee 2017년 11월 20일
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)
Joseph Lee
Joseph Lee 2017년 11월 21일
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 2017년 11월 21일
편집: Joseph Lee 2017년 11월 21일
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
Walter Roberson
Walter Roberson 2017년 11월 21일
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?
Joseph Lee
Joseph Lee 2017년 11월 22일
Only the min out of all the M, one single value.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

질문:

2017년 11월 20일

댓글:

2017년 11월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by