Given the element in a matrix, how to get the corresponding element in cell array?(cell2mat, mat2cell)

조회 수: 2 (최근 30일)
There is a cell array, saying A = {a_1 x b, a_2 x b, a_3 x b, ..., a_n x b}.
After doing B = cell2mat(A), I can get a matrix B, which is (a_1+a_2+...+a_n) x b.
After processing the matrix B, I get my wanted elements in B, saying they are x, which is the row index of Matrix B.
How can I get the corresponding element in original cell A?
For example, if x = 1, it must come from the first element in A. If x > a_1 && x < a_2, it must come from the second element in A.
Is there any function in matlab?
Thanks,
Zhong

채택된 답변

Andrei Bobrov
Andrei Bobrov 2012년 5월 10일
eg
A = arrayfun(@(x)randi(12,randi(6),6),1:7,'un',0)
B = cat(1,A{:})
I=17;J=1;
B(I,J)
%solution
idx = cumsum([0 cellfun('size',A,1)])
nocell = find(idx < I,1,'last')
Ic = I - idx(nocell)
A{nocell}(Ic,J)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by