Call a function within an if statement

1 回表示 (過去 30 日間)
Philine Baumert
Philine Baumert 2022 年 7 月 4 日
コメント済み: Philine Baumert 2022 年 7 月 4 日
Hi all,
I'm writing an experiment and want 3 different types of tasks to be displayed in a random order and to repeat that 5 times but with a changing task order. I've written my tasks as functions (DensityInstruction, DirectionInstruction, SpeedInstruction) so as to call them in my script. The functions on their own are running smoothly, they are stored in the same folder as the script, and I made sure to provide all the necessary input.
If I'm running my script (see below), it's working until after the Shuffle (so I'm getting the randomtasks vector in my workspace) but it doesn't display my functions. It doesn't display any errors or warnings or anything... Any ideas as to why that may be and how to fix it?
try
task = [1 2 3];
ifi = 16.6;
for e = 1:5
randomtasks = Shuffle(task);
for n = 1:length(randomtasks)
if randomtasks==1
vblDensIns = DensityInstruction (ifi);
elseif randomtasks==2
vblDirIns = DirectionInstruction(ifi);
elseif randomtasks==3
vblSpeedIns = SpeedInstruction(ifi);
end
end
end
catch
Screen('CloseAll');
psychrethrow(psychlasterror);
end
Thanks so much in advance!!

採用された回答

Jonas
Jonas 2022 年 7 月 4 日
編集済み: Jonas 2022 年 7 月 4 日
try
randomtasks(n)==1
i guess without the (n) you would compare a vector to a value e.g.
[1 3 2]==1
ans = 1×3 logical array
1 0 0
which is not true and the if is not fullfilled
  1 件のコメント
Philine Baumert
Philine Baumert 2022 年 7 月 4 日
Thanks so much, it works now!

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

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by