设为首页收藏本站

最大的系统仿真与系统优化公益交流社区

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 2415|回复: 0

[交流] 如何在方程中处理字符串变量

[复制链接]
发表于 2009-4-10 13:43:02 | 显示全部楼层 |阅读模式
转自 ExtendSim 英文论坛$ V* j: }" f% {& v. i+ w

8 r; A, x5 u9 a# {Question:
+ `% [# k# w# T9 ]0 u  r* @. S# K7 |$ g* ^+ E
I know that you can use the underlying integer for a string attribute within an equation block.  However, I would like to be able to use the string value.
* R! @* }9 f/ q: ]: X% h  |: tFor example if I have a string attribute called "State" with possible values "PA" and "NC" I know the following equation would work properly:
! `4 G4 a* n7 ?if (State == 1) then
- p2 P" I' }7 u' P- s7 M9 j4 p5 p   outCon0 = 1;" i6 ~! X5 ?) v
elseif (State == 2) then
: b% p1 l( L8 Q   outCon0 = 2;1 j0 l( d" d' A' R2 {- v8 t7 m
else3 x0 O- u* Z' l5 ?
   outCon0 = 0;9 F# \: y0 Z' _5 I: [3 r' G
However, I want the following to work but don't know how in Extend
: T0 B0 G, L4 ^3 \( \& gif (State == "PA") then- Q  C, ^" }9 I3 D+ N8 Q
   outCon0 = 1;
; b; T6 g; Q# \& _elseif (State == "NC") then# n7 @8 E# g5 q) C: K2 X- T; J' z
   outCon0 = 2;( U) l6 B+ T. x9 \5 z1 s; p( O
else) K$ m' @* D! P) N! w, c
   outCon0 = 0;) i  `9 H& T: f  U& j: T( o
& A3 B. S' Q5 V( P1 B1 O# e
2 L! d/ i, x- |7 I+ ?, W3 L
Answer:
7 ~7 ]* \' S; V) S! X+ b/ b" w. o3 x% z; [2 ]" n/ Q
That's a good question. In ExtendSim string attributes are stored as integers which are used as indexes into arrays of strings. This is efficient for both performance and memory. The following equation will get the string from the attribute:
: u! V, `; U. K; I% |
5 ^+ i& R4 n8 r( X% v9 oif(SLStringGet("State", State) == "NC") Path = 0;( d) Q+ X6 E# g& C
else if(SLStringGet("State", State) == "PA") Path = 1;: s/ Q! F6 q. K/ c6 ^! L
else abort;8 q/ L0 V  F  H4 `

9 z& a+ }8 m( Y$ v6 [, b( NI put the abort in at the end so if there was a string that was not in the equation, it would be caught by the model.

评分

参与人数 1仿真币 +20 +2 收起 理由
focuscon + 20 + 2

查看全部评分

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|手机版|SimulWay 道于仿真   

GMT+8, 2024-5-19 17:09 , Processed in 0.013400 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表