## Run a script 5 times whilst changing the value of one parameter each time.

Dursman Mchabe

### Dursman Mchabe (view profile)

님이 질문을 제출함. 17 Dec 2018
최근 활동 Dursman Mchabe

### Dursman Mchabe (view profile)

님이 댓글을 추가함. 19 Dec 2018
Hi everyone
I would like to run the attached script 5 times whilst changing the value of kga from 4e-1 to 4e-2, then 4e-3, then 4e-4, then 4e-5. I would also like to plot the respective results of the repeats on the same set of axis for each respective figure. I would like to ask for help on how to do it.
Regards
Dursman

표시 이전 댓글 수: 20
Dursman Mchabe

### Dursman Mchabe (view profile)

2018 年 12 月 19 日
Thanks a lot for your comment and a very clear explaination. I appreciate that you are providing your expertize. I learn a lot everyday.
I like the idea of using:
function out = mymainfun(vec)
num = numel(vec);
out = cell(1,num);
for k = 1:num
out{k} = Repeat1(vec(k));
end
function results = Repeat1(kga)
... all of your code here. No kga loops!
end
I have implemented it, however, there seems to be an outstanding input. Because I get the error message:
>> mymainfun
Not enough input arguments.
Error in mymainfun (line 2)
num = numel(vec);
>>
I am trying different inputs.
Stephen Cobeldick

### Stephen Cobeldick (view profile)

2018 年 12 月 19 日
I wrote mymainfun so that you could input any vector of kga values without hardcoding them, which means that you will need to call the function with those values, e.g.:
tmp = [4e-1, 4e-2, 4e-3, 4e-4, 4e-5];
out = mymainfun(tmp);
If you prefer to have have hardcoded values then just get rid of the input argument and write that vector inside the function:
function out = mymainfun()
vec = [4e-1, 4e-2, 4e-3, 4e-4, 4e-5];
num = numel(vec);
out = cell(1,num);
for k = 1:num
out{k} = Repeat1(vec(k));
end
end
... etc
You are the code's designer, so these things are entirely up to you.
Dursman Mchabe

### Dursman Mchabe (view profile)

2018 年 12 月 19 日
Thank you so so somuch. The code works 100%. I still have a veery long way to go in learning matlab. But I believe that one day I will be good. I will keep on reading, asking and trying. I thank you so so somuch for everythink that I have learnt yesterday and today.

로그인 to comment.

Translated by