Effacer les filtres
Effacer les filtres

Sequentially load images and generates textures with corresponding names

6 vues (au cours des 30 derniers jours)
Dear community members
My plan is to present images that is named sequentially (i.e., A_01.jpg, A_02.jpg...) on the screen using psychtoolbox functions.
I was stock at the very first step of generating the corresponding textures using the images that are all systematically named A_X.jpg. (X = 1:40) .
( p.s. all images were stored in the same folder)
The script currently looks something like this: (obviously this is very ineffecient)
imageA01 = imread('A_01.jpg,'); % read the image
A01_texture = Screen('Maketexture', windowPtr,imageA01); % generate and neme the texture
% Screen('Maketexture', windowPtr,imageA02) is a psychtoolbox function
% that generate textures that could be "flipped"(i.e., presented on
% the screen) upon screen refreshes
imageA02 = imread('A_02.jpg,');
A02_texture = Screen('Maketexture', windowPtr,imageA02);
imageA03 = imread('A_03.jpg,');
A03_texture = Screen('Maketexture', windowPtr,imageA03);
...
imageA40 = imread('A_40.jpg,');
A40_texture = Screen('Maketexture', windowPtr,imageA40);
I've tried to simplify this using a for loop, but faild to dynamically create and name the individual textures.
Also saw this:
which explicitely stated that we should NOT dynamically name variables, so I was't sure what to do.
Any help or comment is appreciated, thanks in advance.

Réponse acceptée

David Hill
David Hill le 1 Avr 2021
Why not use cell array?
for k=1:40
s=num2str(k);
if length(s)==1
s=['0',s];
end
texture{k}=Screen('Maketexture', windowPtr,imread(sprintf('A_%s.jpg',s));
end
  2 commentaires
Yu Takahashi
Yu Takahashi le 2 Avr 2021
for k=1:40
s=num2str(k);
if length(s)==1
s=['0',s];
end
texture{k}=Screen('Maketexture', windowPtr,imread(sprintf('A_%s.jpg',s)));
% one missing parentheses at the very end
end
Yu Takahashi
Yu Takahashi le 2 Avr 2021
Thanks for the swift reply ! works perfectly!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Timing and presenting 2D and 3D stimuli dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by