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일

1 개 추천

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

jlouise2022
jlouise2022 2022년 2월 16일
Thank you Stephen! This seems to be working! Much appreciated :)
Just a quick follow up question...
I am getting the following error after the first script is executed:
Undefined variable C.
Error in RUN_EXPERIMENT (line 4)
run(C{k})
would appreciate any ideas!
Stephen23
Stephen23 2022년 2월 24일
편집: Stephen23 2022년 2월 24일
"would appreciate any ideas! "
The script/s contain anti-pattern CLEAR (or one of its versions).
Check the scripts, get rid of CLEAR (or CLEAR ALL, CLEARVARS, etc).
Rik
Rik 2022년 2월 24일
You should also consider changing your setup by switching to functions instead of scripts. That way you can avoid most (if not all) of these issues.
jlouise2022
jlouise2022 2022년 2월 25일
Thank you! Removing the CLEAR's did the trick. Will play around with functions too :)
Stephen23
Stephen23 2022년 2월 25일
Converting to functions is not that trivial: it is not possible to use RUN.
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개)

카테고리

도움말 센터File Exchange에서 Audio I/O and Waveform Generation에 대해 자세히 알아보기

제품

릴리스

R2021a

질문:

2022년 2월 16일

편집:

2022년 2월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by