access cell array inside another cell array

Hi,
a short question, I just can't get it running:
I have a 1x94 cell array called A with 94 600x27 cell array inside. Now, as an example, I want to access the following value: 2nd row, 3rd column, 4th cell array. How can I do that?
I want to avoid a "temporary variable" as in:
temp=A{4} value=temp(2,3)
Many thanks, Steffen

댓글 수: 1

Sean de Wolski
Sean de Wolski 2014년 10월 29일
Why do you have this data structure? What is the data and what are you trying to do? There might be a more efficient way.

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

 채택된 답변

Titus Edelhofer
Titus Edelhofer 2014년 10월 29일

5 개 추천

Hi Steffen,
nested indexing should work:
A = cell(1,94);
A{4} = cell(600, 27);
b = A{4}{600,27}
Titus

댓글 수: 4

Steffen
Steffen 2014년 10월 29일
편집: Steffen 2014년 10월 29일
Thank you Titus, that gives me this error: Cell contents reference from a non-cell array object.
So I checked and the 1x94 cell array actually consists of a non-cell array. Their type is double...is it still possible to access them?
EDIT: I converted the rgular array to a cell array now (with num2cell), but if there's an option to access the array directly it would be preferred. Thank you already :)
So what do you have inside the outer cell array A? Is it cells or doubles? If it's double, then access it by
b=A{4}(600,27);
Steffen
Steffen 2014년 10월 29일
Ah, I was blind and always tried
A{4}[600,27];
It works now! Thanks a lot!
Hi Titus Edelhofer! i also have to access the data as it is but my problem is that data in each cell array vary.. e.g;
[21x1 double]
[32x1 double]
[6x1 double]
then please tell me how to access data from this sort of data where the main cell array which contains this type of data is cell.

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

추가 답변 (1개)

N/A
N/A 2017년 5월 4일

3 개 추천

To access 2nd row column three of 4th cell try this code
temp = A{4}(2,3)

댓글 수: 2

How about this case?
>> A = {3, 9, 'a';
'B', [2,4], 0};
>> A(:, 3)
% which spits out
ans =
2×1 cell array
{'a'}
{[0]}
Now I want to access entire row or columns values from this newly extractracted cell. I tried various approach but cause Error: Invalid array indexing. A couple of examples are below:
>> A(:, 3){:, 1}
>> A(:, 3){2, 1}
There is no direct way to do that. You need to either use a temporary variable or a helper function
A = {3, 9, 'a';
'B', [2,4], 0};
%temporary variable
A3 = A(:,3);
A3(2,:)
ans = 1×1 cell array
{[0]}
%helper function
SelectRow = @(object, row) object(row,:);
SelectRow(A(:,3), 2)
ans = 1×1 cell array
{[0]}
The helper function only has to be created once for each context, not for every different place you want to do this kind of indexing.

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

카테고리

도움말 센터File Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

질문:

2014년 10월 29일

댓글:

2023년 2월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by