Matlab:从参数中创建参数表以进行扫描分析

时间:2014-11-26 13:44:18

标签: matlab loops nested

我目前正在模拟材料拉伸时的电阻响应。我有大约10个参数,我想对其中一些进行扫描研究,有时扫描1,2或4个(等)参数而不必过多地修改我的代码。

MWE:

学习功能

function result = mystudy(a,b,c,d,e)
         result = a+b+c+d+e
end

主要

%study of the electric response of a material.
%parameters:
a = 3;
b = 5;
c = 11:13;  %sweeping c 
d = 0:1;    %sweeping d too
e = 25;


%code needed to achieve the following table:
parameter_table = 
3 5 11 0 25
3 5 11 1 25
3 5 12 0 25
3 5 12 1 25
3 5 13 0 25
3 5 13 1 25


for num_study = 1:size(parameter_table,1)

    parameters = { parameter_table(num_study,:) };
    result = mystudy( parameters{:} );
end

以这种方式进行的明显优势:

  • 我总是只有一个循环,不需要根据我想要扫描的参数嵌套循环我的研究。
  • 应该可以启动一项新研究,只需修改%参数下的条目:

我唯一的困难是创建parameter_table,其中每一行都是将要使用的参数集。是否有一种聪明的方法来制作餐桌?

0 个答案:

没有答案