Sequentially load images and generates textures with corresponding names
7 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
David Hill
2021-4-1
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image display and manipulation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!