필터 지우기
필터 지우기

String manipulation (change of a string in a loop)

조회 수: 2 (최근 30일)
boureghda mohammed
boureghda mohammed 2016년 12월 1일
답변: Steven Lord 2016년 12월 1일
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