Re: "Multilevel access cells data"

|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:

Respuestas (1)

Voss
Voss el 14 de Dic. de 2023
"my Cell x is defined as: Cell x = [3x3 double], [4x4 double]"
x = {magic(3),magic(4)} % create x
x = 1×2 cell array
{3×3 double} {4×4 double}
x{:} % show the contents of each cell of x
ans = 3×3
8 1 6 3 5 7 4 9 2
ans = 4×4
16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1
"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
result = 1×2
8 16
"should return [x{1,1}(1,1) x{1,2}(1,1)];"
isequal(result,[x{1,1}(1,1) x{1,2}(1,1)])
ans = logical
1

Categorías

Etiquetas

Preguntada:

el 18 de Jun. de 2016

Respondida:

el 14 de Dic. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by