Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Open dialog for selecting a file with press cancel button

Subject: Open dialog for selecting a file with press cancel button

From: Sprinceana

Date: 13 Mar, 2009 08:30:04

Message: 1 of 3

I have a form test.fig with an axes1 componente and a button of type pushbutton (propery String Load image). When I press the button and I select my image it load me in axes1.


But I want when I press cancel an error dialog appears me with the message: errordlg('File not open!','File Error');


How can I do this?

In pushbutton1 callback I have this:

function pushbutton1_Callback(hObject, eventdata, handles)
filename =uigetfile('*.jpg','*.png','*.bmp') %creation of open dialog with uigetfile function

img=imread(filename); %reads the image
imshow(img); %show image in axes1

if ~filename
    return
end

Subject: Open dialog for selecting a file with press cancel button

From: Steven Lord

Date: 14 Mar, 2009 01:51:11

Message: 2 of 3


"Sprinceana " <mihaispr@yahoo.com> wrote in message
news:gpd5ic$kie$1@fred.mathworks.com...
>I have a form test.fig with an axes1 componente and a button of type
>pushbutton (propery String Load image). When I press the button and I
>select my image it load me in axes1.
>
>
> But I want when I press cancel an error dialog appears me with the
> message: errordlg('File not open!','File Error');

Read the help for UIGETFILE. What is its behavior when the user presses
Cancel? Can you use that behavior to do what you want?

--
Steve Lord
slord@mathworks.com

Subject: Open dialog for selecting a file with press cancel button

From: Zhelyazko

Date: 14 Mar, 2009 02:43:01

Message: 3 of 3

function pushbutton1_Callback(hObject, eventdata, handles)
filename =uigetfile('*.jpg','*.png','*.bmp')
%if the cancel is pressed filename is going to be 0
if ~ischar(filename)
   errordlg('No file Selected!');
   return;
 end

img=imread(filename); %reads the image
imshow(img); %show image in axes1

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us