Code for loading an image question.

Hi everyone,
I have this code for loading an image from the current directory. I can't see anything wrong with it but when I try and load an image from the list it just doesn't seem to display. Could someone quickly check over it and see where I have gone wrong? Sorry, new to MATLAB.
Thanks for your time everyone.

1 commentaire

Luke
Luke le 20 Avr 2013
Modifié(e) : Walter Roberson le 20 Avr 2013
function [] = GUI_25()
D = dir('*.jpg');
S.NAM = {D(:).name};
S.fh = figure('units','pixels','position',[450 450 400 200],'menubar','none','name','Verify Password.','resize','off','numbertitle','off','name','GUI_25');
S.ls = uicontrol('style','list',...
'units','pix',...
'position',[10 60 380 120],...
'backgroundcolor','w',...
'string',S.NAM,...
'HorizontalAlign','left');
S.pb = uicontrol('style','push',...
'units','pix',...
'position',[10 10 380 40],...
'backgroundcolor','w',...
'HorizontalAlign','left',...
'string','Load Image',...
'fontsize',14,'fontweight','bold',...
'callback',{@pb_call,S});
function [] = pb_call(varargin)
S = varargin{3};
L = get(S.ls,{'string';'value'});
try
L = L{1}{L{2}};
X = imread(L);
str = [L(1:end-4),'_',strrep(datestr(now,'HH:MM:SS'),':','_')];
assignin('base',str,X)
catch
fprintf('\t\t%s\n','No file selected, or read error.')
end

Connectez-vous pour commenter.

 Réponse acceptée

Walter Roberson
Walter Roberson le 20 Avr 2013

0 votes

You read the image and assign it to a variable in the base workspace, but you do not have any image() or imshow() call to display the image.

1 commentaire

Walter Roberson
Walter Roberson le 20 Avr 2013
Note: using a dynamic variable name is not a good idea. How is the rest of your program going to know where to look to find the variable with the name you calculate in "str" ?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Images dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by