Run multiple scripts in random order

2 ビュー (過去 30 日間)
jlouise2022
jlouise2022 2022 年 2 月 16 日
編集済み: Stephen23 2022 年 2 月 26 日
Hi Everyone,
I have three scripts for a psychophysics experiment I am running. Lets call them "arrangement1.m", "arragement2.m" and "arrangement3.m". Each script executes a task and collects participant data.
I need to counterbalance/randomise the sequence of the scripts.
I can call the scripts to run sequentially in the command window, but having them run randomly for each participant would be ideal.
Would really appreciate any suggestions!! Many thanks.

採用された回答

Stephen23
Stephen23 2022 年 2 月 16 日
編集済み: Stephen23 2022 年 2 月 16 日
To run scripts you can use RUN:
C = {'arrangement1.m', 'arragement2.m', 'arrangement3.m'};
for k = randperm(numel(C))
run(C{k})
end
Also note that the filename can include an absolute/relative path, for which FULLFILE is very useful.
  8 件のコメント
Rik
Rik 2022 年 2 月 25 日
It is not possible to use run, but using feval is. It is also not as easy to specify a full path (best I can tell you need to cd there and back again), but I don't see a fundamental problem. Am I missing something?
Stephen23
Stephen23 2022 年 2 月 26 日
編集済み: Stephen23 2022 年 2 月 26 日
Using CD has side-effects: it potentially changes other functions too. The general solution of swapping from RUN to FEVAL (or STR2FUNC etc) plus also changing the search path is not trivial... precisely because it changes the search path, which RUN does not. In some limited circumstances it could be done easily.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by