Help on creating structures??
조회 수: 1 (최근 30일)
이전 댓글 표시
The only way I know how to create a structure where all of my sections are ordered is like so:
struct1(1).name='Krista';
struct1(2).name='Kranthi';
struct1(3).name='Kevin';
struct1(4).name='Kalil';
struct1(5).name='Kristen';
struct1(1).date=[10 5 1993];
struct1(2).date=[6 16 1990];
struct1(3).date=[4 20 1991];
struct1(4).date=[7 10 1819];
struct1(5).date=[2 31 1992];
Is there are more concise way to write the code for this and still get the same result?? Help appreciated :) thank you!
댓글 수: 0
채택된 답변
Jacob Halbrooks
2014년 2월 28일
You could enter your data into a two-column cell array and then use CELL2STRUCT:
data = {'Krista', [10 5 1993]; ...
'Kranthi', [6 16 1990]; ...
'Kevin', [4 20 1991]; ...
'Kalil', [7 10 1819]; ...
'Kristen', [2 31 1992]};
s = cell2struct(data, {'name', 'date'},2)
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!