Thread Subject: Odd gui(de) question

Subject: Odd gui(de) question

From: Travis

Date: 8 May, 2009 23:10:02

Message: 1 of 14

I am using GUIDE to creadt a GUI. I have a Browse button set to display the final file path in an editable text field. I chose editable because I like the idea of being able to change it without having to browse again. The problem is that the String is not recorded with the get(hObject,'String) unless I actually type something in there.

Now this does make some sense to me because it is an editable text box and I have not drectly edited it by having it display something from the pushbutton. But is there a way to get to save this without having a "direct" user input?

ps. Works fine with non-editable text and I will use that if nothing else works.

Subject: Odd gui(de) question

From: Travis

Date: 9 May, 2009 01:12:02

Message: 2 of 14

OK, to append to this in I cannot get any default settings for things, mainly buttons, to output at all. If a button is not clicked by the user, no variable is saved. I have a large list of options that effect the way the final code is run, and I have had to manually set the conditions for these using

if isfield(handles.EMMAX) ==0
EEMAX = 1;
end

This however does not affect buttons that are turned off/on via other buttons (not a button group) as it still does not output the value for the changed button. To get the data out I am just using

save('handles','handles').

I

Subject: Odd gui(de) question

From: Bruno Luong

Date: 9 May, 2009 06:50:02

Message: 3 of 14


>
> if isfield(handles.EMMAX) ==0
> EEMAX = 1;
> end

The call is ISFIELD seems fishy to me, does it need 2 arguments?

To set a default string property to a handle , use SET (not GET).

Bruno

Subject: Odd gui(de) question

From: Johnathan

Date: 9 May, 2009 07:17:01

Message: 4 of 14

"Travis" <sinusoid2@hotmail.com> wrote in message <gu2e4a$1js$1@fred.mathworks.com>...
> I am using GUIDE to creadt a GUI. I have a Browse button set to display the final file path in an editable text field. I chose editable because I like the idea of being able to change it without having to browse again. The problem is that the String is not recorded with the get(hObject,'String) unless I actually type something in there.
>
> Now this does make some sense to me because it is an editable text box and I have not drectly edited it by having it display something from the pushbutton. But is there a way to get to save this without having a "direct" user input?
>
> ps. Works fine with non-editable text and I will use that if nothing else works.

I am not sure what you have done, but I think what you are trying to do is something like this:

%PATH TYPER
        jdatapath=uicontrol('Style','edit',...
            'horizontalAlignment','center',...
            'FontWeight','bold',...
            'String',' Path to File',...
            'Position',[c2,r1,300,30],...
            'Value',2500);
        
        %File Browser
        jbrowse=uicontrol('Style','pushbutton',...
            'String','Browse',...
            'Position',[c2+300+10,r1,50,30],...
            'Callback',{@browse_button_Callback});

function browse_button_Callback(object,eventdata)

[cat,carrot]=uigetfile('*.lvm','Select Data File')
browsedatapathway=strcat(carrot,cat)
set(jdatapath,'String',browsedatapathway)

end

if you are using GUIDE, then guide has created the first parts for you, but the important thing is that you use set(handles.editbox,'String',browsedatapathway)

when you try to get(handles.editbox,'String') later, you will retrieve the pathway you selected with the browse function.

hope I haven't misunderstood your question!

--John

Subject: Odd gui(de) question

From: Travis

Date: 9 May, 2009 14:59:02

Message: 5 of 14

Bruno,

What do you mean 2 arguments? I am trying to retrieve the default arguments, I can set them, visually at least, just fine, it just doesn't kick it out when i use sav('handles','handles').

John,

You have no misunderstood my question at all. I think I have exaclty what you are suggesting. Here is the code I have, sorry for not including it in my original post.....

% --- Executes on button press in CoefBrowse.
function CoefBrowse_Callback(hObject, eventdata, handles)
% hObject handle to CoefBrowse (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[CoefFile,CoefPath] = uigetfile('*.mat','Select the Correction Coefficient Matrix');
PathCoef = [CoefPath CoefFile];

set(handles.CoefLoc,'String',PathCoef)


function CoefLoc_Callback(hObject, eventdata, handles)
% hObject handle to CoefLoc (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of CoefLoc as text
% str2double(get(hObject,'String')) returns contents of CoefLoc as a double
MatLoc = get(hObject,'String');

handles.MatLoc = MatLoc;
guidata(hObject,handles)

Subject: Odd gui(de) question

From: Bruno Luong

Date: 9 May, 2009 17:36:01

Message: 6 of 14

"Travis " <sinusoid2@hotmail.com> wrote in message <gu45nm$bng$1@fred.mathworks.com>...
> Bruno,
>
> What do you mean 2 arguments?

You wrote somewhere:

>> isfield(handles.EMMAX)

??? Error using ==> isfield
Not enough input arguments.

>> help isfield
 ISFIELD True if field is in structure array.
    ISFIELD(S,FIELD) returns true if the string FIELD is the name of a
    field in the structure array S.
...

I have no idea what kind of code you post above, it does not even work let alone giving expected behavior.

Bruno

Subject: Odd gui(de) question

From: Travis

Date: 9 May, 2009 18:51:01

Message: 7 of 14

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <gu4eu1$73b$1@fred.mathworks.com>...
> "Travis " <sinusoid2@hotmail.com> wrote in message <gu45nm$bng$1@fred.mathworks.com>...
> > Bruno,
> >
> > What do you mean 2 arguments?
>
> You wrote somewhere:
>
> >> isfield(handles.EMMAX)
>
> ??? Error using ==> isfield
> Not enough input arguments.
>
> >> help isfield
> ISFIELD True if field is in structure array.
> ISFIELD(S,FIELD) returns true if the string FIELD is the name of a
> field in the structure array S.
> ...
>
> I have no idea what kind of code you post above, it does not even work let alone giving expected behavior.
>
> Bruno

Since the handles structure does not export the default position of buttons, etc. If the field EEMAX does not exist it must be in its default state (1); if it does exist then keep the value that it has (0).

Subject: Odd gui(de) question

From: Bruno Luong

Date: 9 May, 2009 19:17:01

Message: 8 of 14

>
> Since the handles structure does not export the default position of buttons, etc. If the field EEMAX does not exist it must be in its default state (1); if it does exist then keep the value that it has (0).

OK now you confuse me big time. I give up, sorry.

Good luck,

Bruno

Subject: Odd gui(de) question

From: Travis

Date: 9 May, 2009 21:16:01

Message: 9 of 14

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <gu4krd$44f$1@fred.mathworks.com>...
> >
> > Since the handles structure does not export the default position of buttons, etc. If the field EEMAX does not exist it must be in its default state (1); if it does exist then keep the value that it has (0).
>
> OK now you confuse me big time. I give up, sorry.
>
> Good luck,
>
> Bruno

hehe, I have confused the great Bruno!! Thank you for trying, and for previous help with other things.

Subject: Odd gui(de) question

From: Johnathan

Date: 9 May, 2009 23:23:01

Message: 10 of 14

>
> John,
>
> You have no misunderstood my question at all. I think I have exaclty what you are suggesting. Here is the code I have, sorry for not including it in my original post.....

HERE'S WHAT I WOULD DO :

 % --- Executes on button press in CoefBrowse.
 function CoefBrowse_Callback(hObject, eventdata, handles)
 % hObject handle to CoefBrowse (see GCBO)
 % eventdata reserved - to be defined in a future version of MATLAB
 % handles structure with handles and user data (see GUIDATA)
 [CoefFile,CoefPath] = uigetfile('*.mat','Select the Correction Coefficient Matrix');
 PathCoef = [CoefPath CoefFile];

%%%%%NEW
 COMBINEDPATHCOEF=STRCAT(CoefPath,CoefFile);
 set(handles.CoefLoc,'String',COMBINEDPATHCOEF)
 %%%%%NEW
 
 function CoefLoc_Callback(hObject, eventdata, handles)
 % hObject handle to CoefLoc (see GCBO)
 % eventdata reserved - to be defined in a future version of MATLAB
 % handles structure with handles and user data (see GUIDATA)
 
 % Hints: get(hObject,'String') returns contents of CoefLoc as text
 % str2double(get(hObject,'String')) returns contents of CoefLoc as a double
 MatLoc = get(hObject,'String');
 
 handles.MatLoc = MatLoc;
 guidata(hObject,handles)


I think this should fix it. You need to combine the two strings you get from uigetfile. I don't know about this MatLoc thing. If you are accessing it this way and it works, that's cool, but with a GUIDE gui you don't have to use guidata. You can just say

variable=get(objecthandle ,'property')
set(otherobjecthandle,'property',variable)

hope you get it straightened out!

--John

Subject: Odd gui(de) question

From: Steven Lord

Date: 11 May, 2009 03:02:22

Message: 11 of 14


"Travis " <sinusoid2@hotmail.com> wrote in message
news:gu4jal$nk4$1@fred.mathworks.com...
> "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message
> <gu4eu1$73b$1@fred.mathworks.com>...
>> "Travis " <sinusoid2@hotmail.com> wrote in message
>> <gu45nm$bng$1@fred.mathworks.com>...
>> > Bruno,
>> >
>> > What do you mean 2 arguments?
>>
>> You wrote somewhere:
>>
>> >> isfield(handles.EMMAX)
>>
>> ??? Error using ==> isfield
>> Not enough input arguments.
>>
>> >> help isfield
>> ISFIELD True if field is in structure array.
>> ISFIELD(S,FIELD) returns true if the string FIELD is the name of a
>> field in the structure array S.
>> ...
>>
>> I have no idea what kind of code you post above, it does not even work
>> let alone giving expected behavior.
>>
>> Bruno
>
> Since the handles structure does not export the default position of
> buttons, etc. If the field EEMAX does not exist it must be in its default
> state (1); if it does exist then keep the value that it has (0).

I understand that's what you want. But that's not what the code you wrote
does. If the handles struct doesn't have a field named EMMAX, then this:

isfield(handles.EMMAX)

will throw an error that handles doesn't have a field named EMMAX (because
it's trying to get the EMMAX field of the handles structure to pass it into
the ISFIELD function.) You want:

if isfield(handles, 'EMMAX')
    % do stuff that depends on handles having a field EMMAX
end

That's what Bruno was asking about.

--
Steve Lord
slord@mathworks.com

Subject: Odd gui(de) question

From: Travis

Date: 11 May, 2009 03:34:01

Message: 12 of 14

"Steven Lord" <slord@mathworks.com> wrote in message
> I understand that's what you want. But that's not what the code you wrote
> does. If the handles struct doesn't have a field named EMMAX, then this:
>
> isfield(handles.EMMAX)
>
> will throw an error that handles doesn't have a field named EMMAX (because
> it's trying to get the EMMAX field of the handles structure to pass it into
> the ISFIELD function.) You want:
>
> if isfield(handles, 'EMMAX')
> % do stuff that depends on handles having a field EMMAX
> end
>
> That's what Bruno was asking about.

Steve you are exactly correct, I typed it in incorrectly. I was able to find something in the blog section on exporting the current state of the buttons and whatnot to a .mat file. Sorry for the confusion.
>
> --
> Steve Lord
> slord@mathworks.com
>

Subject: Odd gui(de) question

From: Travis

Date: 29 May, 2009 15:28:01

Message: 13 of 14

OK, just found an odd thing. I have had the Browse buttons and editable text fields working in perfect sync for a while now, but OI just found that when I hit the 'cancel' button in the browser that pops up using 'uigetdir' the editable text field dissappeared completely.

here is what I have for the button...

% --- Executes on button press in ExBrowse.
function ExBrowse_Callback(hObject, eventdata, handles)
% hObject handle to ExBrowse (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[FileEx,PathEx] = uigetfile({'*.xls'; '*.xlsx'},'Select the Excitation Correction File');
global ExPath
ExPath = [PathEx FileEx];


guidata(hObject,handles);
set(handles.ExLoc,'String',ExPath);

% --- Executes on button press in EmBrowse.
function EmBrowse_Callback(hObject, eventdata%

Subject: Odd gui(de) question

From: Travis

Date: 29 May, 2009 15:30:17

Message: 14 of 14

OK, just found an odd thing. I have had the Browse buttons and editable text fields working in perfect sync for a while now, but OI just found that when I hit the 'cancel' button in the browser that pops up using 'uigetdir' the editable text field dissappeared completely.

here is what I have for the button...

% --- Executes on button press in ExBrowse.
function ExBrowse_Callback(hObject, eventdata, handles)
% hObject handle to ExBrowse (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[FileEx,PathEx] = uigetfile({'*.xls'; '*.xlsx'},'Select the Excitation Correction File');
global ExPath
ExPath = [PathEx FileEx];


guidata(hObject,handles);
set(handles.ExLoc,'String',ExPath);

% --- Executes on button press in EmBrowse.
function EmBrowse_Callback(hObject, eventdata%

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
gui Travis 8 May, 2009 19:14:02
guide Travis 8 May, 2009 19:14:02
editable text Travis 8 May, 2009 19:14:02
rssFeed for this Thread

Contact us at files@mathworks.com