store all array values in a field to a variable
조회 수: 4 (최근 30일)
이전 댓글 표시
I have a test.mat file which contains 1x10 struct array values with 5 fields. The first field 'f' ie,. 'test.f' contains struct array with a dimension of [2x1 double]. I wanted to store all these 10 [2x1 double] values to another variable 'f_vec'. I tried 'getfield'
f_vec = getfield(test,'f')
but it gives out only 1 [2x1 double] value and not all the values from the struct array. when I tried the below command, I got an error.
f_vec = test.f(1,:)
??? Field reference for multiple structure elements that is followed by more
reference blocks is an error.
So all I wanted to do is to store all the [2x1 double] values from 'f' to f_vec. How do I do it ? Thank you.
댓글 수: 0
채택된 답변
추가 답변 (1개)
Azzi Abdelmalek
2014년 1월 28일
편집: Azzi Abdelmalek
2014년 1월 28일
v=struct('a',num2cell(1:10)','f',num2cell(rand(2,10),1)')
out=reshape([v.f],2,10)'
댓글 수: 2
참고 항목
카테고리
Help Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!