MATLAB Answers

0

How to create structure file?

SUSHMA MB 님이 질문을 제출함. 27 Mar 2015
최근 활동 Stephen Cobeldick 님이 편집함. 11 Jan 2016
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?

  댓글 수: 0

로그인 to comment.

태그

답변 수: 2

Umakant 님의 답변 27 Mar 2015

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;

  댓글 수: 0

로그인 to comment.


Stephen Cobeldick 님의 답변 11 Jan 2016
Stephen Cobeldick 님이 편집함. 11 Jan 2016

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})

  댓글 수: 0

로그인 to comment.



Translated by