Clear Filters
Clear Filters

Old value of an updated variable still has an effect on the output (in this particular case). Why?

1 view (last 30 days)
%%First question; please pardon if I didn't provide sufficient/relevant info.
Problem: the value assigned to "that_particular_figure" before the loop messes-up the output.
If you want a bit of context/background: Some images were read (imread), their corresponding textures made (MakeTexture), drawn later (DrawTexture) in this program. The textures are stored in "stimulus_tex". "tex" takes the value of one texture at a time (as per the trial) and it is then, later, drawn. The sequence of the stimuli is of utmost importance here. The "set_of_images" contains all the images whose textures are to be drawn (there are those that are not to be drawn; counterbalanced for each participant) and was used to make the array "stimulus_tex". That is why their index is same, even though the name of the shape (the corresponding number out of 1:24) varies. This loop ensures that the correct texture is put into "tex" for each of the trials. If I use "that_particular_figure" before and then also in the loop, the image sequence goes haywire. ( My guess: the texture is getting assigned both values somehow).
%%This is the code that kind-of does the job. I have just recently started out ...so... still a victim of several malpractices. Suggestions welcomed!
%%running the test
while(1)
for trial = 1:number_of_trials
% set the texture and its position to correspond the current trial
% we have to find out which index of "set_of_images" does "that_particular_figure" correspond to!!!!
% that_particular_figure = stimulus_showing_order(trial);
% this line above ^ is the code that I used when it didn't work properly
assigning_a_different_variable_works = stimulus_showing_order(trial);
for index_in_set_of_images = 1:12 % and whichever "set_of_images" 's index it is, it
% will be at the same index in stimulus_textures
if assigning_a_different_variable_works == set_of_images(index_in_set_of_images)
that_particular_figure = index_in_set_of_images;
else
continue
end
end
% "stimulus_tex" has only 12 cells (textures). The 'number' of our image ranges from 1:24. To find a link between
% this number and it's texture that was made earlier, we use the following logic :-
tex = stimulus_tex{that_particular_figure};
% The textures in "stimulus_tex" and "set_of_images" have the same index. Therefore, by getting the index (from set_of_images)
% of our image number (out of 24), we draw that precise texture.
end
  3 Comments
Amyth
Amyth on 10 Oct 2018
Hi Stephen! Thanks! I didn't use ismember because I didn't know about it. But I'm curious how I could use it in here. From reading a couple examples, I think it compares absolute values among variables. But my variables don't have any common values.
set_of_images contains 12 numbers (ranging 1:24 ), corresponding to each of the 12 randomly selected images. stimulus_tex contains the textures of these 12 images. None of their members are equal to each other, but the indices in both of these correspond such that: if set_of_images(2) = 12, then stimulus_tex(2) will contain the texture of the 12th image.
Also, could you guess why using the same variable twice would have the effect it did? I didn't expect to solve the problem by using separate variables, but it did solve it somehow.
Amyth
Amyth on 10 Oct 2018
Edited: Amyth on 10 Oct 2018
Or did you mean something like this? I feel silly now! XD (But the question still remains)
for trial = 1:10
[~, Locb] = ismember(stimulus_showing_order(trial), set_of_images);
tex = stimulus_tex{Locb};
%etc
%etc
end

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!