Sequentially load images and generates textures with corresponding names
7 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
David Hill
on 1 Apr 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 Comments
More Answers (0)
See Also
Categories
Find more on Image display and manipulation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!