How to access struct fields within cell array?
조회 수: 22 (최근 30일)
이전 댓글 표시
Hello there, I have a 50*1 cell array and every cell-element is a 100*1 cell-array, whose elements are from type struct. And I want to have the field values. I have tried something like this:
X = cell(length, 1)
for i
for j
X{i}{j} = Bigcellarray{i}{j}.field
end
end
This does not work, has anybody an idea? Greetings!
댓글 수: 2
James Tursa
2017년 7월 30일
편집: James Tursa
2017년 7월 30일
This is unclear. Are you trying to build such a cell array from variables you already have? If so, can you provide us exactly with what variables you have (class and size) to start with?
KSSV
2017년 7월 31일
To write a code for that.....we should know the structure perfect. Attach your data as .mat file, so that you can get a help.
답변 (2개)
Akira Agata
2018년 7월 10일
Then, how about the following? After running this, A is 100-by-50 numeric array where A(i,j) = Bigcellarray{i}{j}.field
C = [Bigcellarray{:}];
A = cellfun(@(x) x.field, C)';
댓글 수: 0
Walter Roberson
2017년 7월 31일
N = length(Bigcellarray);
X = cell(N, 1);
for i = 1 : N
for j = 1 : length(Bigcellarray{i})
X{i}{j} = Bigcellarray{i}{j}.field
end
end
참고 항목
카테고리
Help Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!