String manipulation (change of a string in a loop)

2 次查看(过去 30 天)
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 个评论
boureghda mohammed
boureghda mohammed 2016-12-1
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

请先登录,再进行评论。

回答(1 个)

Steven Lord
Steven Lord 2016-12-1
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

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by