MATLAB Answers

Problems with Indexing of cell array

4 views (last 30 days)
PR on 26 May 2018
Edited: Ameer Hamza on 27 May 2018
Hi guys!
The problem I have is the following: I have a dictionary with names and with one picture. I create a randomized sequence for my pictures. Now I want to display (via Psychtoolbox) the respective Name Cues for the image, but in randomized order. Hopefully my code snippet does show you what I mean:
nameCues1 = {'Lisa','Anna', 'Sarah', 'Nina', 'resized_1.jpg' };
nameCues2 = {'Emma', 'Lena', 'Gabi', 'Steffi', 'resized_2.jpg' };
nameCues3 = {'Tanja', 'Luisa', 'Jana', 'Nicole', 'resized_3.jpg' };
nameCues4 = {'Clara', 'Tina', 'Katja', 'Susi', 'resized_4.jpg' };
I have loaded them into a cell array:
nameCuesAll = {nameCues1,nameCues2, nameCues3}
Now I create a randomized sequence:
randSeq3 = nameCuesAll(randperm(size(nameCuesAll,2)));
%%Loop for Rating Phase
% Reads facial stimuli for "Explicit Recognition Phase"
for i = 1:numel(nameCuesAll)
pics3{i} = imread(randSeq3{i}{1,5});
ind{i}=randSeq3{i}{ind}; %this doesn't work yet!
Then I prompt in on the Screen via the function of Psychtoolbox:
for j = 1:4
%%here I leave out some unnecessary functions of Psychtoolbox
DrawFormattedText(window,ind{i}(j), 'center', 'center', white, [], [], [], [], [], rect);
I put in some hard hours, but didn't come close to a sufficient solution. I would be very glad if someone could help me out here.
Thanks so much!


Show 2 older comments
Ameer Hamza
Ameer Hamza on 27 May 2018
does produce an output like 2,3,1,4,5 but what do you expect from the output of
Let's make the example concrete. For example if
randSeq3{1} = {'Emma', 'Lena', 'Gabi', 'Steffi', 'resized_2.jpg' }
will produce something like 2,3,1,4,5. What do you expect the value of ind{1} after
PR on 27 May 2018
will produce something like 2,3,1,4,5. What do you expect the value of ind{1} after
Yeah, the last one is with wrong syntax, thanks. I wanted to use this vector (2,3,1,4,5 -for example) as input for the function:
DrawFormattedText(window,ind{i}(j), 'center', 'center', white, [], [], [], [], [], rect);
so that this function prompts: a) the picture (of, for example, names1) b) the 4 names in randomized order (of, for example, names1).
But that doesn't work, MATLAB throws several errors, most commonly that subsscripting is not allowed for cells. I have no idea how to solve that unfortunately which is why I asked here...
Best, PR
Ameer Hamza
Ameer Hamza on 27 May 2018
I am not sure, but it appears that you want to do something like this
You might want to go through indexing concepts in MATLAB

Sign in to comment.

Answers (0)

Sign in to answer this question.