필터 지우기
필터 지우기

Assigning Attributes to the entity in simulink

조회 수: 4 (최근 30일)
summyia qamar
summyia qamar 2018년 3월 4일
댓글: summyia qamar 2018년 3월 17일
I want to generate parts from a single Entity Generator block. the attributes attached with the parts are Part type and Service Time. I have tried this
what I understood from my code is that the first entity generated will get Type attribute randomly from 1 to 3 and service time will be 2 but I want that each entity generated with attribute Type 1, e.g. get service time=2 and entity with Type 2 get Service time=4 etc. But I dont know how to write the syntax. Can anybody guide me please?

채택된 답변

Brian Neiswander
Brian Neiswander 2018년 3월 17일
You can use a switch statement to assign values to the ServiceTime attribute depending on the value of the Type attribute.
entity.Type = randi(3);
switch(entity.Type)
case 1
entity.ServiceTime = 2;
case 2
entity.ServiceTime = 4;
case 3
entity.ServiceTime = 10;
end
In the code above, the Type attribute is randomly assigned a value of either 1, 2, or 3. The ServiceTime attribute is assigned a value of
  • 2 when entity.Type==1,
  • 4 when entity.Type==2,
  • 10 when entity.Type==3.
With this approach, each entity generated will be of Type 1, 2, or 3 and have a ServiceTime of 2, 4, or 10, respectively.
  댓글 수: 1
summyia qamar
summyia qamar 2018년 3월 17일
thankyou sir.. this platform is a great source of learning and enhancing matlab programming skills

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Discrete-Event Simulation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by