Clear Filters
Clear Filters

String manipulation (change of a string in a loop)

2 views (last 30 days)
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 Comment
boureghda mohammed
boureghda mohammed on 1 Dec 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

Sign in to comment.

Answers (1)

Steven Lord
Steven Lord on 1 Dec 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

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!