How to merge multiple scripts in MATLAB

조회 수: 18 (최근 30일)
Mobeen
Mobeen 2014년 7월 8일
댓글: Mobeen 2014년 7월 19일
Hi,
I am running an analysis using SPM, and want to run multiple scripts at once. One way to do this is to copy and paste each subject's script into a new one and run them together. However, this is quite time consuming considering I have 155!
Therefore, I was wondering if there is an easier way to merge multiple script files in MATLAB?
Thank you, M
  댓글 수: 1
Mobeen
Mobeen 2014년 7월 19일
My apologies for the confusion. When I originally referred to 'batches', I was talking about the gooey in SPM whereby one can create a batch to carry out multiple things at once (e.g. Realignment, Normalisation, Smoothing, etc.). My question was with regards to the script files that can be created by clicking "Save As... Batch and Script" (which creates a .job file and a .m file).
I was looking for an easier way to run multiple scripts, aside from copying and pasting them into one long script and running that.
Thank you for your help, M

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

답변 (2개)

Titus Edelhofer
Titus Edelhofer 2014년 7월 8일
Hi,
you might just create a script that uses "run" to run the other scripts based on the output of "dir"? Something like
batchFiles = dir('PathToBatchfiles\*.m');
for i=1:length(batchFiles)
run(fullfile('PathToBatchfiles', batchFiles(i).name));
end
Titus
  댓글 수: 2
Mobeen
Mobeen 2014년 7월 8일
Thank you for your reply!
Forgive my inexperience with MATLAB, but for some reason this doesn't do anything when I run it having changed the directory name. Are there any other changes to be made?
mfazal
Titus Edelhofer
Titus Edelhofer 2014년 7월 10일
Most probably the path is wrong. What does "batchFiles" look like? Is it empty, i.e., of size 0x1 or something similar?

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


Joseph Cheng
Joseph Cheng 2014년 7월 10일
when you say batch file are you talking about *.bat files? if so then you are not looking for run() command. you'll be wanting to use system() or dos() or ! (exclamation-mark) to run a bat file.
see the documentation (doc system) on how to use it.

카테고리

Help CenterFile Exchange에서 Troubleshooting in MATLAB Compiler SDK에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by