Sequentially load images and generates textures with corresponding names

7 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

David Hill
David Hill el 1 de Abr. de 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 comentarios
Yu Takahashi
Yu Takahashi el 2 de Abr. de 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 el 2 de Abr. de 2021
Thanks for the swift reply ! works perfectly!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Image display and manipulation en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by