How to create structure file?

조회 수: 14 (최근 30일)
SUSHMA MB
SUSHMA MB 2015년 3월 27일
편집: Stephen23 2016년 1월 11일
I want to create a structure file of 1x20, with fields 'x,y,type,cost'. And i also want to assign different values for each struct. How to do this?

답변 (2개)

Umakant
Umakant 2015년 3월 27일
The following code creates 1x20 structure, each with four fields:
mystruct(20).x =1
mystruct(20).y =2
mystruct(20). type=3
mystruct(30).cost=4;

Stephen23
Stephen23 2016년 1월 11일
편집: Stephen23 2016년 1월 11일
Read this and try some of its examples:
nums(1).f = 1;
nums(2).f = 2;
nums(3).f = 3;
allNums = [nums.f]
Note that you can create the complete non-scalar structure all at once using struct, which might be the easiest option for you:
S = struct('f',{1,2,3})

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by