From: Marc Crapeau on
"Rajesh " <rv_acharya(a)rediffmail.com> wrote in message <hohtje$ecl$1(a)fred.mathworks.com>...
>
> > The solution for me was simply to explicitly set the Value of the box at
> > the time the uicontrol was created. As that is better programming
> > practice anyhow, I just always do that now.
>
> God, How i wish Mr. Walter roberson could also tell how to set it at the time of creation.
> I changed the 'Value' field in the property inspector to 1.0 and the default state changed to 'checked' from previous 'unchecked' but i am afraid my var1 is still an empty matrix.
> :(
> I am using R2007a btw.

Just change your "if var1==0" with "if var1==0 | isempty(var1)" :p
From: ImageAnalyst on
On Mar 26, 5:09 am, "Rajesh " <rv_acha...(a)rediffmail.com> wrote:
> God, How i wish Mr. Walter roberson could also tell how to set it at the time of creation.
> I changed the 'Value' field in the property inspector to 1.0 and the default state changed to 'checked' from previous 'unchecked' but i am afraid my var1 is still an empty matrix.
> :(
> I am using R2007a btw.  
--------------------------------------------------------------------------------
Well you could use GUIDE like I do. I never have that problem. I can
create a checkbox and it's value is either 0 or 1 depending on what it
looks like in GUIDE (unchecked or checked). It's never empty as far
as I know. If you don't want to use GUIDE, then maybe you can use it
to just create a sample GUI and then tell it to build an m-file from
it (File -> Export...) and look to see how it instantiates the
checkbox. Then use the code in your code where you tediously
construct a GUI from individual components. In fact I did that and
here is how it does it:

h2 = uicontrol(...
'Parent',h1,...
'Units','characters',...
'Callback',@(hObject,eventdata)checkboxtest_export('checkbox1_Callback',hObject,eventdata,guidata(hObject)),...
'Position',[11.8 24.4615384615385 20.2 3.15384615384615],...
'String',{ 'Check Box' },...
'Style','checkbox',...
'Tag','checkbox1',...
'CreateFcn', {@local_CreateFcn, blanks(0), appdata} );

If I don't do anything to the check state (it starts out unchecked)
and just run it, and retrieve the value like this
checkboxValue = get(handles.checkbox1, 'Value')
it says that checkboxValue is a 1x1 double with a value of 0.


From: Rajesh on
@Marc:
I am using the same thing (isempty).
@imageanalyst
I did not follow you. How can i use GUIDE only for a part of the GUI when all other controls are generated not through GUIDE. Can you elaborate.
Thanks anyways friends. I was stuck somewhere hence the delay.
From: Bruno Luong on
"Rajesh " <rv_acharya(a)rediffmail.com> wrote in message <hof1o2$sug$1(a)fred.mathworks.com>...
>
> hi,
> sorry for the delay i am afraid i dint get a notification. anyway.
>
> may be my question was not clear. let me elaborate. I have a checkbox on a GUI. when i run the GUI i see the checkbox unchecked on the interface. Lets call it the default state. Now in the callback function of the box i have written
>
> global var1
> var1=get(hObject,'Value');
>
> further, I am using var1 as a condition to skip (if var1==0) or perform (if var1==1) a certain loop in another callback.
>

My guess is the problem caused by or missused of GLOBAL, it has nothing to do with checkbox state. The value of checkbox must be 0 or 1, never empty.

For example such error happens as following: "var1" would never set if you the callback is not invoked, so it remains empty. This is programming error because you don't fully understand the data flow of your program and GUI callback mechanism.

Bruno
From: Walter Roberson on
Bruno Luong wrote:
> The value of checkbox must be 0 or 1, never
> empty.

It has been noted by some users that in at least some versions, if you
construct a checkbox without setting an initial value, then the value of
the checkbox when fetched will be the empty array.

My experience has been that if the checkbox is given an initial value
when constructed, or via set(), that the checkbox will then operate
normally, but there have been some claims that in at least some
versions, no matter what initial value is given to a checkbox, it will
be fetched as the empty array until there is user interaction with the
checkbox.

If I recall correctly, I encountered the uninitialized -> empty value
behaviour myself in at least one version.
First  |  Prev  |  Next  |  Last
Pages: 1 2 3
Prev: power system studies
Next: need help about xcorr