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

조회 수: 275(최근 30일)
SC 2019년 3월 17일
편집: Stephen23 2019년 3월 17일
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!

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

### 채택된 답변

Stephen23 2019년 3월 17일
편집: Stephen23 2019년 3월 17일
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

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

### 범주

Find more on Structures in Help Center and File Exchange

R2018b

### Community Treasure Hunt

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

Start Hunting!

Translated by