# How to read the details of a '1×1 struct' Cell Array?

107 visualizzazioni (ultimi 30 giorni)
SC il 17 Mar 2019
Modificato: Stephen23 il 17 Mar 2019
Hi,
I have a variable called L1, which is a '1×1 struct' Cell Array. I want to extract the details of this variable, but I tried different functions including fieldnames(), fields() and struct2table(), and all of them doesn't work.
I put the variable inside a small .mat file as attached (L1.mat). How can I access the details of the variable? Thanks!
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Stephen23 il 17 Mar 2019
Modificato: Stephen23 il 17 Mar 2019
Both cell arrays and structure arrays are kinds of container arrays, i.e. they can contain other arrays. In your case you actually have a scalar cell array containing a scalar structure. This is easy to check:
>> class(L1) % tells us L1 is a cell array
ans = cell
>> size(L1) % tells us L1 is scalar
ans =
1 1
Now that we know that L1 is a cell array, the obvious thing to do is to find out what it contains, which we can do easily using basic cell array indexing:
>> S = L1{1}; % allocate the content of that cell to a variable S.
>> class(S) % tells us S is a structure
ans = struct
>> size(S) % tells us S is scalar
ans =
1 1
Now that we know that scalar cell array L1 contains a scalar structure, it is easy to access the structure's fields or do any other structure operations with it:
>> C = fieldnames(L1{1}); % the fieldnames of the structure inside the cell array,
>> C = fieldnames(S); % or equivalently the fieldnames of the structure by itself.
>> C{:}
ans = name
ans = type
ans = weights
ans = size
ans = stride
ans = precious
ans = dilate
ans = opts
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Structures in Help Center e File Exchange

R2018b

### Community Treasure Hunt

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

Start Hunting!

Translated by