The images do not appear on the screen. What is wrong with the code?

I tried to run the whole program, but it got stuck after Line 145 (only the instruction slide, and the blank screen with fixation cross that appear on the screen). It won't get into the 'if loop' with the target images. When I tried to put some of the lines in 'if loop' just before the loop (before Line 151), the images appear on the screen. I am guessing it might be something wrong the way I wrote the condition matrix (Line 74 - 95?) and the way I call the condition in 'if loop' (Line 151 onwards). Can someone help me to figure out what is wrong with the code?
Thank you.
Regards, Sabrina

 Accepted Answer

When you do things like
elseif condVector(:,2)==3;
that is only true if every row in the column vector (column 2 of condVector) is non-zero. Usually people don't want this and you should use any(condVector(:,2)==3) or all(condVector(:,2)==3). I'm not sure what you want, so you should look into it. By the way, you don't need a semicolon at the end of ifs or elseifs.

3 Comments

Hi Image Analyst, Thank you for your prompt response. I have different conditions in each trial (as specified in condTable matrix), and for the 'if loop', I want to display a different image for different condition. For example, if for all in column 2 of the conVector, if the value is 3, it should display a specific image. So in that case, should I use any(condVector(:,2)==3) instead?
How many rows are in condVector(:,2)? Let's say there's 10. And let's say 2 of them have a value of 3 and the other 8 have some other value. What do you want to do in that case?
if they have a value of 3, they should display the image specified in the line, if not the program should read the next few lines of code to call the image for the specific value. I think I have now understood what you mean. I have tried to change it to any(condVector) and it's now working. Thank you so much Image Analyst.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!