imshow command will not display my images
30 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi all, I am currently trying to randomly present 21 images, one after the other, all located within the same folder. When I run my code, Matlab does not display any errors, but no images are shown either. I currently have the following code;
dirname= 'C:\Users\User\Documents\MATLAB\stimuli\';
d=dir([dirname '*.jpg']);
for i= randperm(numel(d))
imshow(d(i).name)
pause(2);
end
0 Kommentare
Antworten (3)
KSSV
am 29 Jan. 2019
d=dir([dirname '*.jpg']);
for i= randperm(numel(d))
I = imread(d(i).name) ;
imshow(I)
pause(2);
end
1 Kommentar
Walter Roberson
am 29 Jan. 2019
dirname= 'C:\Users\User\Documents\MATLAB\stimuli\';
d=dir(fullfile(dirname, '*.jpg'));
for i = randperm(numel(d))
imshow( fullfile(dirname, d(i).name) )
pause(2);
end
0 Kommentare
Stephen23
am 29 Jan. 2019
Bearbeitet: Stephen23
am 29 Jan. 2019
The reason is very simple: you forgot to use the path when you tried to read the file:
D = 'C:\Users\User\Documents\MATLAB\stimuli';
S = dir(fullfile(D,'*.jpg'));
for k = randperm(numel(S))
imshow(fullfile(D,S(k).name))
pause(2);
end
Note that it is recommended to avoid using i for a loop iterator, as this is the name of the imaginary unit. Using fullfile is recommended instead of string concatenation:
0 Kommentare
Siehe auch
Kategorien
Mehr zu Image Processing Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!