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.

 Respuesta aceptada

Star Strider
Star Strider el 6 de Abr. de 2015
One way to approach your problem:
CapextResult = @(Capext) ((Capext == 0)*[0 0] + (Capext == 50)*[0.6 570] + (Capext == 95)*[0.8 900] + (Capext == 120)*[1.1 1030]);
CapextVct = [0,50,95,120];
for k1 = 1:length(CapextVct)
CapextTest(k1,:) = CapextResult(CapextVct(k1));
end

2 comentarios

Cristian Hernandez
Cristian Hernandez el 6 de Abr. de 2015
i'd like to know if "@(Capext)" is a function you've created or is the variable that controls the other two variables
The function name is ‘CapextResult’. It is an anonymous function The ‘@(Capext)’ part tells MATLAB that it is an anonymous function and that its argument is ‘Capext’.
To get ‘Cuext’ and ‘Cauext’ from the function, you simply need to assign them:
Cuext = CapextTest(:,1);
Cauext = CapextTest(:,2);

Iniciar sesión para comentar.

Más respuestas (1)

Sean de Wolski
Sean de Wolski el 6 de Abr. de 2015
Editada: Sean de Wolski el 6 de Abr. de 2015
Here's a small example with synthetic values and variable names:
% c is independent, cdep is dependent on c
c = [0 25 90 100];
cdep = [1 34 56 78]
n = randi(numel(c),1) % random choice
cex = c(n) % Extrac
cdex = cdep(ismember(c,cex)) % grab corresponding one

Categorías

Preguntada:

el 6 de Abr. de 2015

Comentada:

el 6 de Abr. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by