필터 지우기
필터 지우기

Sequentially load images and generates textures with corresponding names

조회 수: 6 (최근 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.

채택된 답변

David Hill
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
  댓글 수: 2
Yu Takahashi
Yu Takahashi 2021년 4월 2일
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 2021년 4월 2일
Thanks for the swift reply ! works perfectly!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Timing and presenting 2D and 3D stimuli에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by