Effacer les filtres
Effacer les filtres

String manipulation (change of a string in a loop)

2 vues (au cours des 30 derniers jours)
boureghda mohammed
boureghda mohammed le 1 Déc 2016
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 commentaire
boureghda mohammed
boureghda mohammed le 1 Déc 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

Connectez-vous pour commenter.

Réponses (1)

Steven Lord
Steven Lord le 1 Déc 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

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by