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 件のコメント

Luke
Luke 2013 年 4 月 20 日
編集済み: Walter Roberson 2013 年 4 月 20 日
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

サインインしてコメントする。

 採用された回答

Walter Roberson
Walter Roberson 2013 年 4 月 20 日

0 投票

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 件のコメント

Walter Roberson
Walter Roberson 2013 年 4 月 20 日
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" ?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeImages についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by