access cell array inside another cell array
Show older comments
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 Comment
Sean de Wolski
on 29 Oct 2014
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.
Accepted Answer
More Answers (1)
N/A
on 4 May 2017
3 votes
To access 2nd row column three of 4th cell try this code
temp = A{4}(2,3)
2 Comments
monkeyquant
on 3 Feb 2023
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,:)
%helper function
SelectRow = @(object, row) object(row,:);
SelectRow(A(:,3), 2)
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.
Categories
Find more on Operators and Elementary Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!