Path: news.mathworks.com!newsfeed-00.mathworks.com!panix!bloom-beacon.mit.edu!llnews!53ab2750!not-for-mail
From: Peter Boettcher <boettcher@ll.mit.edu>
Newsgroups: comp.soft-sys.matlab
Subject: Re: : [ ] function?
References: <g5sevj$ra1$1@fred.mathworks.com>
Message-ID: <muyvdyz6qse.fsf@G99-Boettcher.llan.ll.mit.edu>
Organization: MIT Lincoln Laboratory
User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/23.0.0 (gnu/linux)
Cancel-Lock: sha1:O8KIa6OpAIP7T/ltLzgOYoStHAw=
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Lines: 53
Date: Mon, 21 Jul 2008 14:22:25 -0400
NNTP-Posting-Host: 155.34.163.114
X-Complaints-To: news@ll.mit.edu
X-Trace: llnews 1216663803 155.34.163.114 (Mon, 21 Jul 2008 14:10:03 EDT)
NNTP-Posting-Date: Mon, 21 Jul 2008 14:10:03 EDT
Xref: news.mathworks.com comp.soft-sys.matlab:480730



"ching l" <chinglnc@hotmail.com> writes:

> Peter Boettcher <boettcher@ll.mit.edu> wrote in message
> <muyzlob6td6.fsf@G99-Boettcher.llan.ll.mit.edu>...
>> "ching l" <chinglnc@hotmail.com> writes:
>> 
>> > Thanks Peter. That's really helpful. I sort of get the idea
>> > of doing this in Matlab command, but not in Gui. As I'm not
>> > so sure how to create a Matrix function. That's what I
>> > thought which I did it in Matlab. 
>> >
>> > a= [1, 2, 3];
>> > b= [a;1, 2, 3];
>> > c= [b; 1, 2, 3];
>> >
>> > then finally write the matrix into text file.
>> >
>> > But Gui doesn't understand what is 
>> > a= [1, 2, 3]; because that's not a function. 
>> >
>> > What I want is, when the callback function is called, it can
>> > create a= [1, 2, 3]. As simple as that.
>> 
>> Don't change how you create or call the callback function.  Just put
>> that code in the body of the callback function.  The header of the
>> function, and the 'Callback' property of the GUI, will look exactly
>> the same as it did before.
>> 
>> -Peter
>
> Did I miss something? That's what I did but nothing
> happened....did you mean this?
>
> function  answer_nochange_Callback(hObject, eventdata, handles)
>
> a= [1, 2, 3];

Yes, I mean this.  And it does exactly what you told it to.  It creates
a variable "a" in the workspace of the callback function.  Now go back
to what you did before to store "randValue", so that it would be
accessible from one callback to the next.

Do you get that's why you have to do all that stuff with handles and
guidata?  Like all functions, once the callback function exits, all its
variables disappear.  When you want data to persist, you have to do
something else with it.  And the most natural thing when you're writing
a GUI is to associate your persistent data with the GUI itself, which is
exactly what "handles" and "guidata" are for.

Now take that code that someone else helped you with and extend the
concept to this other stuff you'd like to do now.

-Peter