Variables with especific posible values
Info
This question is closed. Reopen it to edit or answer.
Show older comments
Hi, i'm trying to define some variables that only can take one of some defined values, and depending of wich value results for this variable, other variabe take a value. for example:
i have this variable: Capext, this must take one of this values :
/0,50,95,120/ and if Capext = 0, then Cuext = 0 and Cauext = 0 Capext = 50, then Cuext = 0.6 and Cauext = 570 Capext = 95, then Cuext = 0.8 and Cauext = 900 Capext = 120, then Cuext = 1.1 and Cauext = 1030
i don't know how to use or define as variables that three. i´ve tried to define a set ( i /1*4/) and the variables as parameters depending of "i", but it didn't work. i've tried to define all that as a table but now i think it's not possible, because i need that as variables, and i need to know which value is taken for the model.
i would be grateful if one you can help me.
Answers (1)
John D'Errico
on 6 Apr 2015
Edited: John D'Errico
on 6 Apr 2015
Nothing personal, but I'd strongly suggest rethinking those variable names. They are difficult to see the difference between them, and you WILL end up with buggy code, that will be sheer hell to debug.
As for the actual assignments, it LOOKS like you can just use an if statement. I say it looks that way, because your explanation is VERY confusing and impossible to read. One long strung out set of ands and thens, involving the variables Capext, Cuext, Cauext.
You should also be able to use a table, or ismember, or a switch case construct.
Personally, I think you can just use a switch case, as the simplest way to write it.
switch Capext
case 0
Cuext = 0;
Cauext = 0;
case 50
Cuext = .6;
Cauext = 570;
case 95
Cuext = .8;
Cauext = 900;
case 120
Cuext = 1.1;
Cauext = 1030;
end
You should get the idea. I doubt I got it right, because my eyes are bleary just from trying to read that long line of yours.
1 Comment
Eric
on 6 Apr 2015
I agree with John that the original post is hard to decipher. But you might also look at the containers.Map object in Matlab. I find this helpful at times for issues such as this.
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!