let a script run in other script with variable parameters

3 views (last 30 days)
I want to let a script (ex: project.m) run in other script (ex: main.m) with changing parameters.
It means, the parameters is set in the main.m script and the project.m is loaded from the main.m and runs in a for-loop with the defined parameters.
Thank you so much for your answer!
Best Regards,
Minyoung
  2 Comments

Sign in to comment.

Accepted Answer

Abderrahim. B
Abderrahim. B on 4 Jul 2022
Hi Minyoung ,
You can run a matlab script inside another this way :
run('project.m')
A good practice is to create a function from your script project.m and call it then in you main:
Function project.m
function [outArg1, outArg2,..,outArgN] = project(inArg1, inArg2, ..,inArgN )
yourCodeHere
end
main.m
% parameters
% call your function
M = 10 ;
for ii = 1:M
[outArg1, outArg2,..,outArgN] = project(inArg1, inArg2, ..,inArgN ) ;
end

More Answers (1)

Jonas
Jonas on 4 Jul 2022
it really sounds like you actally should change your script to a fcuntion. Running a script giving paramters to it is exactly what a function is
  2 Comments
Minyoung Hong
Minyoung Hong on 4 Jul 2022
I solved my problem with function! thanks for your tip again. However I gave @Abderrahim BELISSAOUI the acceptance because he gave me the answer more detail. But I am also really thankful for you!

Sign in to comment.

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by