Azzera filtri
Azzera filtri

String manipulation (change of a string in a loop)

2 visualizzazioni (ultimi 30 giorni)
Hi, I have a function f(x1,x2,x3), I want to explore the sensitivity of each parameters on the function f. I wrote the code (is not relay the code but a description)
variabDim=val;
x1=val1; x2=val2;x3=val3; real values of the variables
UB=[val1,val2,val3]; Lower bound for the variables
LB=[val1,val2,val3]; Upper bound for the variables
for i =1:variabDim
for x1 = LB(i):(UB(i)-LB(i))/numpoint:UB(i)
x= [x1,x2,x3];
f(x);
end
what I want to ask is, how can I make the string x1 change in the second loop to x2 and x3 with the change of i.
  1 Commento
boureghda mohammed
boureghda mohammed il 1 Dic 2016
The important to me from this question is how can I make the string x1 to change in the second loop to x2 and x3 with the change of i, for example in the code below how can I make param(1) in the second loop to be replaced by the variable x1 and so on.
param=[x1,x2,x3]
for i=1:variablDim
for param(i) = 0:0.01:10
x = [x1,x2,x3];
f(x);
end
end

Accedi per commentare.

Risposte (1)

Steven Lord
Steven Lord il 1 Dic 2016
Don't think of it as changing a variable name. Think of it as changing which element of the vector you modify.
base = [1 2 3];
for whichElement = 1:3
for newvalue = 5:10
x = base;
x(whichElement) = newvalue;
disp(x)
end
end

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by