From: dpb on
Dave ba wrote:
....

> in my case the code that resets the variable to zero is in the callback
> of the button that plots the graph, but this is also the place where the
> variable is created. In fact, its the same line. and I need to put it to
> zero to create it.

As we've discussed before, that's the problem--you don't want the
initialization code in the callback routine; you're mixing apples w/ the
pineapples by doing so...

> but as I said before, putting that code on another place just creates a
> detour for it (to put it back to zero), you'll eventually have the same
> end results. that's how I see it at least..
>
> then I thought, maybe I could use the IF statement to fix the problem.
> say that IF the variable has a value attached that isn't 0, then dont
> reset it.
> but then the code to create the variable still must not be repeated over
> and over again.
> so, is there a way to execute a piece of code only once in a program
> even though it comes back several times in the running of the program?

Dave...
Again, read the GUI help section on handling data -- in my version
there's an example of a Slider control w/ an initialized variable
(numberOfErrors) added to the handles structure for a very similar
purpose. That example uses GUIDE to create the GUI so it uses that
default structure (handles) but the next section talks about
user-defined structures and accessing same.

Again, I repeat -- therein is your solution I'm virtually positive and
that you're currently heading down the wrong path by not looking into
the structure that Matlab generates expressly for the purpose of
handling GUI data but trying to find some way other to use non-GUI
techniques w/ a GUI app...

--
From: Dave ba on
sorry, I'm just no pro at Matlab. but I've read 'Managing GUI data'.
and I've followed the 'Creating and Updating GUI Data' section.
but I still can't get it right.
I just gonna post a new message, because I don't think that anyone know what the question in this one is anymore...
From: Andro on
"Dave ba" <nummers123(a)hotmail.com> wrote in message <hov06l$dbr$1(a)fred.mathworks.com>...
> sorry, I'm just no pro at Matlab. but I've read 'Managing GUI data'.
> and I've followed the 'Creating and Updating GUI Data' section.
> but I still can't get it right.
> I just gonna post a new message, because I don't think that anyone know what the question in this one is anymore...

HI!
I have the solution!Somewhat unusual but it works!
So, what have I done:
1. create variable in Matlab workspace
2. in my callback function load variable from Matlab workspace
3. store data which is read from serial port into this variable
4. export back to the Matlab workspace (where the value is of course also stored and GUI can't handle it)

You can access stored variable later from everywhere in your GUI wit evalin...

The code looks like this:

In the opening function:
handles.data=0; %Variable declaring
assignin('base','data',handles.data); %To the Matlab workspace

In ma callback function:

handles.data=evalin('base','data'); %Load variable from base workspace
handles.data(1,sample)=t; %First row of my matrice
handles.data(2,sample)=temperature; %Second row
assignin('base','data',handles.data); %export back to Matlab workspace

Have fun!
Andro
From: dpb on
Dave ba wrote:
> sorry, I'm just no pro at Matlab. but I've read 'Managing GUI data'. and
> I've followed the 'Creating and Updating GUI Data' section. but I still
> can't get it right. I just gonna post a new message, because I don't
> think that anyone know what the question in this one is anymore...

Couldn't you copy the idea of the slider example???

If you do post a different/new thread, I'd suggest making a short sample
code that others can paste that demonstrates the problem/desired result
that you're having trouble with. Obviously, this should be as short as
possible but contain the essence...

--
First  |  Prev  | 
Pages: 1 2 3
Prev: Generalized Ridge Regression
Next: 2d dct type-1