let a script run in other script with variable parameters

조회 수: 12 (최근 30일)
Minyoung Hong
Minyoung Hong 2022년 7월 4일
댓글: Minyoung Hong 2022년 7월 4일
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
Abderrahim. B
Abderrahim. B 2022년 7월 4일
Hi Minyoung ,
Correct me if i am mistaken .
  • You have the script main.m that has the paramters
  • and a seperate matlab script project.m
  • then you are trying to call project.m in the main.m to loop on it .
Please clarify so we can provide you with answers!
Minyoung Hong
Minyoung Hong 2022년 7월 4일
@Abderrahim BELISSAOUI exactly and with the parameters from the main.m

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

채택된 답변

Abderrahim. B
Abderrahim. B 2022년 7월 4일
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

추가 답변 (1개)

Jonas
Jonas 2022년 7월 4일
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
Minyoung Hong
Minyoung Hong 2022년 7월 4일
Thank you for your tip. Now, I am trying to do it with function.
Minyoung Hong
Minyoung Hong 2022년 7월 4일
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!

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

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by