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:
GUI question

Subject: GUI question

From: Phil Au

Date: 18 Feb, 2008 01:54:03

Message: 1 of 7

Hi All,

I got an question about my GUI matlab,

If I got two axes, if I want to one of the axes to display
an img, how can I write it in code, pls,

many thx...

And also when I use the filesparts function, when I press
the cancelbutton

I get this error~~


?? Error using ==> fileparts at 17
Input must be a row vector of characters.

Error in ==> appl>browse_Callback at 143
[pathstr,name,ext,versn] = fileparts(get
(handles.inputimg_ed,'string'));

Error in ==> gui_mainfcn at 96
        feval(varargin{:});

Error in ==> appl at 42
    gui_mainfcn(gui_State, varargin{:});

??? Error while evaluating uicontrol Callback


Can you pls help me to solve it?











Here's my code

function browse_Callback(hObject, eventdata, handles)
% hObject handle to browse (see GCBO)
% eventdata reserved - to be defined in a future version
of MATLAB
% handles structure with handles and user data (see
GUIDATA)
[pathstr,name,ext,versn] = fileparts(get
(handles.inputimg_ed,'string'));
if ~isempty(pathstr),
    pathstr = [pathstr '\'];
end
try
    [file,path] = uigetfile([pathstr '*.jpg'],'Select an
image');
    set(handles.inputimg_ed,'string',[path file]);
    info = imfinfo([path file]);
    set(handles.width_ed,'string',info.Width);
    set(handles.height_ed,'string',info.Height);
    imshow([path file]);
catch
end

Subject: GUI question

From: Vihang Patil

Date: 18 Feb, 2008 04:42:03

Message: 2 of 7

"Phil Au" <philipawt@gmail.com> wrote in message
<fpaofr$ru7$1@fred.mathworks.com>...
> Hi All,
>
> I got an question about my GUI matlab,
>
> If I got two axes, if I want to one of the axes to display
> an img, how can I write it in code, pls,
>
> many thx...
>
Answer to your first question

axes(handles.axes1); %assuming axes1 is the name of the
first %axes
imshow(yourimage);

HTH
VIhang

Subject: GUI question

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 18 Feb, 2008 04:52:56

Message: 3 of 7

In article <fpaofr$ru7$1@fred.mathworks.com>,
Phil Au <philipawt@gmail.com> wrote:

>And also when I use the filesparts function, when I press
>the cancelbutton

>I get this error~~

>?? Error using ==> fileparts at 17
>Input must be a row vector of characters.

>Here's my code
>

> [file,path] = uigetfile([pathstr '*.jpg'],'Select an image');

What is the documented output result when you cancel a uigetfile
dialog?
--
  "Why does he stagger his mind with the mathematics of the sky?
  Once the question mark has arisen in the human brain the answer must
  be found, if it takes a hundred years. A thousand years."
                                              -- Walter Reisch

Subject: GUI question

From: Phil Au

Date: 18 Feb, 2008 10:49:02

Message: 4 of 7

Hi Walter,

Thx for your reply first.
It was used in the Browse button, whem i press the button,
it was supposed to select an image file and if I selected a
file, it will display the path of the file in an edit box,
and diplay the details of the img and the actual img.

But I i press the cancel button, the edit box which used to
display the path of the file is disappeareed and when I
press the button again, I got this error..

Thanks for your time and help


>
> >And also when I use the filesparts function, when I
press
> >the cancelbutton
>
> >I get this error~~
>
> >?? Error using ==> fileparts at 17
> >Input must be a row vector of characters.
>
> >Here's my code
> >
>
> > [file,path] = uigetfile([pathstr '*.jpg'],'Select an
image');
>
> What is the documented output result when you cancel a
uigetfile
> dialog?
> --
> "Why does he stagger his mind with the mathematics of
the sky?
> Once the question mark has arisen in the human brain
the answer must
> be found, if it takes a hundred years. A thousand
years."
> -- Walter
Reisch

Subject: GUI question

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 18 Feb, 2008 11:29:28

Message: 5 of 7

In article <fpbnqu$2in$1@fred.mathworks.com>,
Phil Au <philipawt@gmail.com> wrote:

>Thx for your reply first.
>It was used in the Browse button, whem i press the button,
>it was supposed to select an image file and if I selected a
>file, it will display the path of the file in an edit box,
>and diplay the details of the img and the actual img.

>But I i press the cancel button, the edit box which used to
>display the path of the file is disappeareed and when I
>press the button again, I got this error..

You use fileparts -first- and then you use uigetfile. So any
problem with uigetfile will not be reflected until the -next-
time you call the function.


>> > [file,path] = uigetfile([pathstr '*.jpg'],'Select an
>image');

>> What is the documented output result when you cancel a
>uigetfile
>> dialog?

To answer my hint to you myself: when the user cancels
uigetfile, the return value is the -number- 0, not
a string. You then store that 0 in a handle, and the next
call around, you pull the numeric 0 out and try to use it
in fileparts, which promptly complains because you have not
passed fileparts a string.
--
   "Beware of bugs in the above code; I have only proved it correct,
   not tried it." -- Donald Knuth

Subject: GUI question

From: ImageAnalyst

Date: 18 Feb, 2008 14:19:54

Message: 6 of 7

On Feb 18, 6:29=A0am, rober...@ibd.nrc-cnrc.gc.ca (Walter Roberson)
wrote:
> In article <fpbnqu$2i...@fred.mathworks.com>,
>
> Phil Au <philip...@gmail.com> wrote:
> >Thx for your reply first.
> >It was used in the Browse button, whem i press the button,
> >it was supposed to select an image file and if I selected a
> >file, it will display the path of the file in an edit box,
> >and diplay the details of the img and the actual img.
> >But I i press the cancel button, the edit box which used to
> >display the path of the file is disappeareed and when I
> >press the button again, I got this error..
>
> You use fileparts -first- and then you use uigetfile. So any
> problem with uigetfile will not be reflected until the -next-
> time you call the function.
>
> >> > =A0 =A0[file,path] =3D uigetfile([pathstr '*.jpg'],'Select an
> >image');
> >> What is the documented output result when you cancel a
> >uigetfile
> >> dialog?
>
> To answer my hint to you myself: when the user cancels
> uigetfile, the return value is the -number- 0, not
> a string. You then store that 0 in a handle, and the next
> call around, you pull the numeric 0 out and try to use it
> in fileparts, which promptly complains because you have not
> passed fileparts a string.
> --
> =A0 =A0"Beware of bugs in the above code; I have only proved it correct,
> =A0 =A0not tried it." =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0-- Donald Knuth

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
It's issues like this that make me wish MATLAB were a strongly typed
language like most other programming languages, where you were
required to declare variables of a certain type before you could use
them, and they maintained that type every time you used them. I know
you give up some flexibility in being able to write fast, sloppy code
but other languages agree that that "advantage" does not outweigh the
potential problems it causes.
Regards,
ImageAnalyst

Subject: GUI question

From: Phil Au

Date: 19 Feb, 2008 01:38:02

Message: 7 of 7

Hi Walter,
Thx again for the reply, I edited the code as below, now i
dont have the error, but i can't use the browse button if
I press the cancel, Do you know how can I still use the
browse button even I press the cancel button

try
    [pathstr,name,ext,versn] = fileparts(get
(handles.inputimg_ed,'string'));
    if ~isempty(pathstr),
        pathstr = [pathstr '\'];
    else
        [pathstr,name,ext,versn] = fileparts(get
(handles.inputimg_ed,'string'));
    end
    [file,path] = uigetfile([pathstr '*.jpg'],'Select an
image');
    if isequal(pathstr,0)
        set(handles.inputimg_ed,'string','cancelled');
    else
        set(handles.inputimg_ed,'string',[path file]);
    end
    info = imfinfo([path file]);
    set(handles.width_ed,'string',info.Width);
    set(handles.height_ed,'string',info.Height);
    imshow([path file]);
catch



btw, do you know why I got an Warning: Single line Edit
Controls can not have multi-line text.













roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
message <fpbq6o$4e2$1@canopus.cc.umanitoba.ca>...
> In article <fpbnqu$2in$1@fred.mathworks.com>,
> Phil Au <philipawt@gmail.com> wrote:
>
> >Thx for your reply first.
> >It was used in the Browse button, whem i press the
button,
> >it was supposed to select an image file and if I
selected a
> >file, it will display the path of the file in an edit
box,
> >and diplay the details of the img and the actual img.
>
> >But I i press the cancel button, the edit box which used
to
> >display the path of the file is disappeareed and when I
> >press the button again, I got this error..
>
> You use fileparts -first- and then you use uigetfile. So
any
> problem with uigetfile will not be reflected until the -
next-
> time you call the function.
>
>
> >> > [file,path] = uigetfile([pathstr '*.jpg'],'Select
an
> >image');
>
> >> What is the documented output result when you cancel a
> >uigetfile
> >> dialog?
>
> To answer my hint to you myself: when the user cancels
> uigetfile, the return value is the -number- 0, not
> a string. You then store that 0 in a handle, and the next
> call around, you pull the numeric 0 out and try to use it
> in fileparts, which promptly complains because you have
not
> passed fileparts a string.
> --
> "Beware of bugs in the above code; I have only proved
it correct,
> not tried it." --
Donald Knuth

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