Best Way to Convert Data in a Structure to an Array

조회 수: 3 (최근 30일)
Sonoma Rich
Sonoma Rich 2021년 2월 26일
편집: Stephen23 2021년 2월 26일
I am doing the following to convert data in a structure to an array. It seems a little clunky. Is there a better way?
a(1).data = [1 2];
a(2).data = [3 4];
a(3).data = [5 6];
a(4).data = [7 8];
data2 = cell2mat({a.data}');
  댓글 수: 2
Bob Thompson
Bob Thompson 2021년 2월 26일
You don't need to do the cell2mat conversion, you can just use vertcat.
data2 = vertcat(a(:).data);
I don't have a good way to make your definition of a.data any better.
Stephen23
Stephen23 2021년 2월 26일
편집: Stephen23 2021년 2월 26일

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by