Problems with Indexing of cell array

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}=randperm(numel(randSeq3{i}));
ind{i}=randSeq3{i}{ind}; %this doesn't work yet!
end
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);
end
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!

5 个评论

The syntax is wrong since you are trying to pass a cell array as indexing vector. But if you can explain what are you trying to do in that line, it might be possible to suggest a solution.
Hi, first of all, thank you very much for your quick reply!
Firstly, the idea is that I want to show the picture of a dictionary set (for example the picture of "nameCues1") with the corresponding names in that dictionary. The problem now is that I manage to prompt the pictures with the names, but: the names are not randomized. The pictures with the right corresponding names are shown randomly, but the names in the four boxes are not randomized.. That is my main problem.
What I tried in the wrong index was that I wanted first create a shuffled sequence of the nameCues via
randSeq3 = nameCuesAll(randperm(size(nameCuesAll,2)))
and then, as it is a cell array, I wanted to shuffle the cells with the names in it via:
ind{i}=randperm(numel(randSeq3{i}))
this, I thought, would create an order like "2,4,1,3" which I would give back as a handle to the prompting function, but I don't manage to solve this issue...
ind{i}=randperm(numel(randSeq3{i}))
does produce an output like 2,3,1,4,5 but what do you expect from the output of
ind{i}=randSeq3{i}{ind};
Let's make the example concrete. For example if
randSeq3{1} = {'Emma', 'Lena', 'Gabi', 'Steffi', 'resized_2.jpg' }
Then
ind{1}=randperm(numel(randSeq3{i}));
will produce something like 2,3,1,4,5. What do you expect the value of ind{1} after
ind{1}=randSeq3{1}{ind};
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
I am not sure, but it appears that you want to do something like this
ind{i}=randSeq3{i}(randperm(numel(randSeq3{i})));
You might want to go through indexing concepts in MATLAB

请先登录,再进行评论。

回答(0 个)

类别

帮助中心File Exchange 中查找有关 Timing and presenting 2D and 3D stimuli 的更多信息

提问:

PR
2018-5-26

Community Treasure Hunt

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

Start Hunting!

Translated by