"ching l" <chinglnc@hotmail.com> wrote in message
<g5sevj$ra1$1@fred.mathworks.com>...
> this might sound stupid or simple....can I do something like
> this in matlab?
>
> a= 1, 2, 3 ;
>
> function(a)= [1, 2, 3]
>
>
> is there such function?
What are you asking for? Are you asking
for a function that acts like the [] operator?
Horzcat is that function, or vertcat, or cat.
Are you asking for a function that returns
a constant vector, or something like that?
I'm quite confused by your question.
"John D'Errico" <woodchips@rochester.rr.com> wrote in
message <g5sgum$epd$1@fred.mathworks.com>...
> "ching l" <chinglnc@hotmail.com> wrote in message
> <g5sevj$ra1$1@fred.mathworks.com>...
> > this might sound stupid or simple....can I do something like
> > this in matlab?
> >
> > a= 1, 2, 3 ;
> >
> > function(a)= [1, 2, 3] Re
> >
> >
> > is there such function?
>
> What are you asking for? Are you asking
> for a function that acts like the [] operator?
> Horzcat is that function, or vertcat, or cat.
>
> Are you asking for a function that returns
> a constant vector, or something like that?
> I'm quite confused by your question.
>
> John
I want to have this in a gui,whenever the call back function
is called, it will create something like this....
function pushbutton7_Callback(hObject, eventdata, handles)
"ching l" <chinglnc@hotmail.com> wrote in message
<g5sjom$jhc$1@fred.mathworks.com>...
> "John D'Errico" <woodchips@rochester.rr.com> wrote in
> message <g5sgum$epd$1@fred.mathworks.com>...
> > "ching l" <chinglnc@hotmail.com> wrote in message
> > <g5sevj$ra1$1@fred.mathworks.com>...
> > > this might sound stupid or simple....can I do something like
> > > this in matlab?
> > >
> > > a= 1, 2, 3 ;
> > >
> > > function(a)= [1, 2, 3] Re
> > >
> > >
> > > is there such function?
> >
> > What are you asking for? Are you asking
> > for a function that acts like the [] operator?
> > Horzcat is that function, or vertcat, or cat.
> >
> > Are you asking for a function that returns
> > a constant vector, or something like that?
> > I'm quite confused by your question.
> >
> > John
>
> I want to have this in a gui,whenever the call back function
> is called, it will create something like this....
>
> function pushbutton7_Callback(hObject, eventdata, handles)
>
> Callback 1= [1, 2, 3])
> Callback 2= [Callback 1: 4, 5, 6])
> Callback 3= [Callback 2: 7, 8, 9])
> Callback 4 = csvwrite ('string', [callback 3+ callback 4])
>
> does it make sense?
>
Sorry, but no sense at all.
> Callback 1= [1, 2, 3])
Are you asking how to create a syntax error? ;-)
"Callback 1"
Is not the name of a valid variable in MATLAB.
Ending the line with a spare ) is also a
good way to create a syntax error.
Likewise, I have no idea what you intend
by the following:
> Callback 2= [Callback 1: 4, 5, 6])
Disregarding the other syntax errors I
already mentioned, what do you want the
colon operator to do in the middle of that
expression?
Finally, I have no idea how this question
bears on the subject title, which indicated
a question about [] as a function.
Sorry, but I'm way more confused than I
was before.
"John D'Errico" <woodchips@rochester.rr.com> wrote in
message <g5sm5j$ou9$1@fred.mathworks.com>...
> "ching l" <chinglnc@hotmail.com> wrote in message
> <g5sjom$jhc$1@fred.mathworks.com>...
> > "John D'Errico" <woodchips@rochester.rr.com> wrote in
> > message <g5sgum$epd$1@fred.mathworks.com>...
> > > "ching l" <chinglnc@hotmail.com> wrote in message
> > > <g5sevj$ra1$1@fred.mathworks.com>...
> > > > this might sound stupid or simple....can I do
something like
> > > > this in matlab?
> > > >
> > > > a= 1, 2, 3 ;
> > > >
> > > > function(a)= [1, 2, 3] Re
> > > >
> > > >
> > > > is there such function?
> > >
> > > What are you asking for? Are you asking
> > > for a function that acts like the [] operator?
> > > Horzcat is that function, or vertcat, or cat.
> > >
> > > Are you asking for a function that returns
> > > a constant vector, or something like that?
> > > I'm quite confused by your question.
> > >
> > > John
> >
> > I want to have this in a gui,whenever the call back function
> > is called, it will create something like this....
> >
> > function pushbutton7_Callback(hObject, eventdata, handles)
> >
> > Callback 1= [1, 2, 3])
> > Callback 2= [Callback 1: 4, 5, 6])
> > Callback 3= [Callback 2: 7, 8, 9])
> > Callback 4 = csvwrite ('string', [callback 3+ callback 4])
> >
> > does it make sense?
> >
>
> Sorry, but no sense at all.
>
> > Callback 1= [1, 2, 3])
>
> Are you asking how to create a syntax error? ;-)
>
> "Callback 1"
>
> Is not the name of a valid variable in MATLAB.
>
> Ending the line with a spare ) is also a
> good way to create a syntax error.
>
> Likewise, I have no idea what you intend
> by the following:
>
> > Callback 2= [Callback 1: 4, 5, 6])
>
> Disregarding the other syntax errors I
> already mentioned, what do you want the
> colon operator to do in the middle of that
> expression?
>
> Finally, I have no idea how this question
> bears on the subject title, which indicated
> a question about [] as a function.
>
> Sorry, but I'm way more confused than I
> was before.
>
> John
ahh sorry, those codes are not properly coded, it just an
expression of what I want...
Basically, the final outcome of the callback (or after the
push button is pressed) is a TEXT FILE, with the
corresponded information.
I want these 1, 2, 3,
4, 5, 6,
7, 8, 9
to be in the text file.
Meaning to say, when the push button is first pressed, it
will create [1, 2, 3 ], then when it's pressed again,
it will create [1, 2, 3, ; 4, 5, 6], and then when it's
pressed again, it will create [1, 2, 3; 4, 5, 6; 7, 8, 9] so
on and so forth. Then when the final push button is pressed,
it will create a text file with all these information in there.
Does it make sense now?
p.s. sorry, it was not supposed to be : in the previous post.
> > > I want to have this in a gui,whenever the call back
function
> > > is called, it will create something like this....
> Meaning to say, when the push button is first pressed, it
> will create [1, 2, 3 ], then when it's pressed again,
> it will create [1, 2, 3, ; 4, 5, 6], and then when it's
> pressed again, it will create [1, 2, 3; 4, 5, 6; 7, 8, 9] so
> on and so forth. Then when the final push button is pressed,
> it will create a text file with all these information in
there.
>
> Does it make sense now?
>
> p.s. sorry, it was not supposed to be : in the previous post.
> Basically, the final outcome of the callback (or after the
> push button is pressed) is a TEXT FILE, with the
> corresponded information.
>
> I want these 1, 2, 3,
> 4, 5, 6,
> 7, 8, 9
>
> to be in the text file.
>
> Meaning to say, when the push button is first pressed, it
> will create [1, 2, 3 ], then when it's pressed again,
> it will create [1, 2, 3, ; 4, 5, 6], and then when it's
> pressed again, it will create [1, 2, 3; 4, 5, 6; 7, 8, 9] so
> on and so forth. Then when the final push button is pressed,
> it will create a text file with all these information in there.
I think you have already learned how to store values in "handles". So
keep going with that concept. You will have two values in "handles".
One is the "number" of the callback. That is, it starts at 0
(initialize it as the GUI starts, like you did last time), and
increments each time the button is pushed.
The other value in "handle" is the matrix. As the callback is called,
look at the first value to decide how many times the button was pushed
already. Add your new number to the matrix appropriately. And write
the file when the number is > 3. Or whenever you want.
To learn MATLAB, or any programming language, it is an essential skill
to be able to separate a problem into small pieces. In this case:
Handle a button push via a callback.
Store values between different callbacks.
Execute different code based on a condition.
Append rows to a matrix.
Write a text file.
Etc, etc.
Some of these you know how to do already. Some you may need to try to
read the documentation. And some you may need to post here. Once you
have a plan, start coding. Either go for broke and write it all,
debugging after that, or start with the bare minimum that will show
something. Like increment the count (and display it) each time the
button is pushed. That will make it easier to write and debug the rest.
In article <g5soo2$1ej$1@fred.mathworks.com>,
ching l <chinglnc@hotmail.com> wrote:
>Basically, the final outcome of the callback (or after the
>push button is pressed) is a TEXT FILE, with the
>corresponded information.
>I want these 1, 2, 3,
> 4, 5, 6,
> 7, 8, 9
>to be in the text file.
>Meaning to say, when the push button is first pressed, it
>will create [1, 2, 3 ], then when it's pressed again,
>it will create [1, 2, 3, ; 4, 5, 6], and then when it's
>pressed again, it will create [1, 2, 3; 4, 5, 6; 7, 8, 9] so
>on and so forth. Then when the final push button is pressed,
>it will create a text file with all these information in there.
>Does it make sense now?
I already gave you a coded solution to this question in your thread
"go to next function in one callback".
--
"When we all think alike no one is thinking very much."
-- Walter Lippmann
Peter Boettcher <boettcher@ll.mit.edu> wrote in message
<muyprp78hzv.fsf@G99-Boettcher.llan.ll.mit.edu>...
> "ching l" <chinglnc@hotmail.com> writes:
>
> > Basically, the final outcome of the callback (or after the
> > push button is pressed) is a TEXT FILE, with the
> > corresponded information.
> >
> > I want these 1, 2, 3,
> > 4, 5, 6,
> > 7, 8, 9
> >
> > to be in the text file.
> >
> > Meaning to say, when the push button is first pressed, it
> > will create [1, 2, 3 ], then when it's pressed again,
> > it will create [1, 2, 3, ; 4, 5, 6], and then when it's
> > pressed again, it will create [1, 2, 3; 4, 5, 6; 7, 8, 9] so
> > on and so forth. Then when the final push button is
pressed,
> > it will create a text file with all these information in
there.
>
> I think you have already learned how to store values in
"handles". So
> keep going with that concept. You will have two values in
"handles".
> One is the "number" of the callback. That is, it starts at 0
> (initialize it as the GUI starts, like you did last time), and
> increments each time the button is pushed.
>
> The other value in "handle" is the matrix. As the
callback is called,
> look at the first value to decide how many times the
button was pushed
> already. Add your new number to the matrix appropriately.
And write
> the file when the number is > 3. Or whenever you want.
>
>
> To learn MATLAB, or any programming language, it is an
essential skill
> to be able to separate a problem into small pieces. In
this case:
>
> Handle a button push via a callback.
> Store values between different callbacks.
> Execute different code based on a condition.
> Append rows to a matrix.
> Write a text file.
> Etc, etc.
>
> Some of these you know how to do already. Some you may
need to try to
> read the documentation. And some you may need to post
here. Once you
> have a plan, start coding. Either go for broke and write
it all,
> debugging after that, or start with the bare minimum that
will show
> something. Like increment the count (and display it) each
time the
> button is pushed. That will make it easier to write and
debug the rest.
>
>
>
> -Peter
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.
> 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 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)
> 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 Boettcher <boettcher@ll.mit.edu> wrote in message
<muyvdyz6qse.fsf@G99-Boettcher.llan.ll.mit.edu>...
> "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
my problem is, it doesnt do this- "It creates a variable "a"
in the workspace of the callback function"...
> Peter Boettcher <boettcher@ll.mit.edu> wrote in message
> <muyvdyz6qse.fsf@G99-Boettcher.llan.ll.mit.edu>...
>> "ching l" <chinglnc@hotmail.com> writes:
>>
>> >
>> >
>> > 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
>
> my problem is, it doesnt do this- "It creates a variable "a"
> in the workspace of the callback function"...
Why do you think it doesn't? Like I explain above, the variable is
created, then the callback function exits and the variable immediately
disappears.
"Matt Fig" <spamanon@yahoo.com> wrote in message
<g62mlh$hug$1@fred.mathworks.com>...
>
> >
> > my problem is, it doesnt do this- "It creates a variable "a"
> > in the workspace of the callback function"...
>
>
> Take off the semicolon. If you see the variable a printed
> to the command window, then yes it does create it in the
> callback.
>
ahhh!! such a silly mistake!! I really thought it's doing
nothing because there is no variable in the workspace!
"Matt Fig" <spamanon@yahoo.com> wrote in message
<g62mlh$hug$1@fred.mathworks.com>...
>
> >
> > my problem is, it doesnt do this- "It creates a variable "a"
> > in the workspace of the callback function"...
>
>
> Take off the semicolon. If you see the variable a printed
> to the command window, then yes it does create it in the
> callback.
>
What is the reason the callback of handles.id is always
return 0 regardless the number that I put in the edit text box?
%% Edit Text
function subject_ID_CreateFcn(hObject, eventdata, handles)
handles.id= get(hObject, 'Value');
guidata(hObject, handles);
In article <g62r22$4hr$1@fred.mathworks.com>,
ching l <chinglnc@hotmail.com> wrote:
>What is the reason the callback of handles.id is always
>return 0 regardless the number that I put in the edit text box?
If that is the Callback for a uicontrol('Style','edit')
then you need to be aware that the Value of an edit box
is *always* 0. If you want the string content of an edit box,
you need to retrieve it's String property.
--
"We may gather out of history a policy, by the comparison and
application of other men's forepassed miseries with our own like
errors and ill deservings." -- Sir Walter Raleigh
Tags for this Thread
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.
Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for
all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content.
Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available
via MATLAB Central. Read the complete Disclaimer prior to use.