Re: "Multilevel access cells data"
Afficher commentaires plus anciens
|In the link at the bottom there are several examples. Here are 2-examples:
C{1,1}(1,2)
Returns: ans = 2;
x{1,1}(1:2)
Returns (2-values): ans = 7, 8
My Qn: Can i retrieve values across sub-cells?
For example my Cell x is defined as:
Cell x =
[3x3 double], [4x4 double]
Can i retrieve x{1}(1,1) and x{2}(1,1) in a single statement?
Like:
x{1:2}(1,1); % Attempt to retrieve 2-values across 2 sub-cells
Statement above should return
[x{1,1}(1,1) x{1,2}(1,1)];
However i'm getting an error
Relevant link See:
Réponses (1)
"my Cell x is defined as: Cell x = [3x3 double], [4x4 double]"
x = {magic(3),magic(4)} % create x
x{:} % show the contents of each cell of x
"Can i retrieve x{1}(1,1) and x{2}(1,1) in a single statement?"
result = cellfun(@(c)c(1,1),x) % store element (1,1) from each cell of x in result
"should return [x{1,1}(1,1) x{1,2}(1,1)];"
isequal(result,[x{1,1}(1,1) x{1,2}(1,1)])
Catégories
En savoir plus sur Multidimensional Arrays dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!