필터 지우기
필터 지우기

how to run function for several times with different variables

조회 수: 18 (최근 30일)
Asliddin Komilov
Asliddin Komilov 2019년 3월 5일
댓글: Stephen23 2019년 3월 12일
I have something like this:
a=5
b=8
c=9
d=11
%a,b,c and d are function inputs
n=a*0.1:a*0.1:a
for i=1:length(n)
"function"
end
but I need to run function replacing 'a' in 'n' with 'b','c' and 'd' at once and save the data so I can compare it. it is a sensitivity analysis for this function outputs.
  댓글 수: 2
dpb
dpb 2019년 3월 5일
To do every point for all four variables would be quad-nested for loops and you'd end up with 4^10= 1048576 outputs. Depending on how expensive function() is in compute time, this might take a while...
Typically one uses response surface methods or similar to do such studies that replace the detail function with a (typically) quadratic surface over the design space. (Myers, RH, Response Surface Methodology, Allyn and Bacon, 1971 was my "go to" and still a favorite).
Asliddin Komilov
Asliddin Komilov 2019년 3월 12일
that is too difficult for me, I did it for each variable separately (see below). thank you

댓글을 달려면 로그인하십시오.

답변 (2개)

Dennis
Dennis 2019년 3월 5일
In your example you do not need more than one variable:
a=[5 8 9 11];
for i=1:numel(a)
n=a(i)*0.1:a(i)*0.1:a(i);
for k=1:numel(n)
%function
end
end
  댓글 수: 2
dpb
dpb 2019년 3월 5일
"but I need to run function replacing 'a' in 'n' with 'b','c' and 'd'..."
Asliddin Komilov
Asliddin Komilov 2019년 3월 12일
thanks, but it gave error inside th function, so I decided to skip it.

댓글을 달려면 로그인하십시오.


Asliddin Komilov
Asliddin Komilov 2019년 3월 12일
편집: Stephen23 2019년 3월 12일
I just saved the loop for each variable.
a=5
b=8
c=9
d=11
%a,b,c and d are function inputs
n=a*0.1:a*0.1:a
for i=1:length(n)
"function"
end
save file_a
a=a(end);
clear "function outputs"
%--------------------------
n=b*0.1:b*0.1:b
for i=1:length(n)
"function"
end
save file_b
b=b(end);
clear "function outputs"
%---------------------------
..........
  댓글 수: 1
Stephen23
Stephen23 2019년 3월 12일
You could save the bother by simply putting your data into one array and using indexing.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by