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 Comment

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

Sign in to comment.

 Accepted Answer

Walter Roberson
Walter Roberson on 20 Apr 2013
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 Comment

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" ?

Sign in to comment.

More Answers (0)

Categories

Find more on Images in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!