Thread Subject: I want to make a handle/pointer to a non-handle dataset...

Subject: I want to make a handle/pointer to a non-handle dataset...

From: Ken Fuller

Date: 11 Jun, 2009 05:45:03

Message: 1 of 4

I have a question that has been bugging me (he he he) a long time.

Why doesn't matlab have some kind of ability to make a pointer/handle to a non-handle dataset?


What I want to do is to save a pointer of an object in a GUI using the GUIDATA function, but I don't want the original object to be of the handle class.

Specifically, I made a class that has some methods that create some plots. I want the
plots to be able to update in both directions. Ie if the user adds data to the object,
the plots update, or if the user changes the plot itself, the data in the object will
update. To make the object update the plot is easy. To make the plot update the object, without the object being inherited as a handle class, is hard. The reason it's hard is because any reference I put into the GUI is a copy of the object, not a link to the original.

Oh yeah, I don't want the object to be a handle class because some users, especially the new ones, like the pass-by-value programming style better than the pass-by-reference style.

Any help will be greatly appreciated!

Subject: I want to make a handle/pointer to a non-handle dataset...

From: Steven Lord

Date: 11 Jun, 2009 14:01:04

Message: 2 of 4


"Ken Fuller" <kfuller5@juno.com> wrote in message
news:h0q5kv$bqh$1@fred.mathworks.com...
>I have a question that has been bugging me (he he he) a long time.
>
> Why doesn't matlab have some kind of ability to make a pointer/handle to a
> non-handle dataset?
>
>
> What I want to do is to save a pointer of an object in a GUI using the
> GUIDATA function, but I don't want the original object to be of the handle
> class.
>
> Specifically, I made a class that has some methods that create some plots.
> I want the
> plots to be able to update in both directions. Ie if the user adds data
> to the object,
> the plots update, or if the user changes the plot itself, the data in the
> object will
> update. To make the object update the plot is easy. To make the plot
> update the object, without the object being inherited as a handle class,
> is hard. The reason it's hard is because any reference I put into the GUI
> is a copy of the object, not a link to the original.

So from this description of the behavior you want the object to have, you
_do_ want the object to be a handle object, so that copies are "links" to
the original.

> Oh yeah, I don't want the object to be a handle class because some users,
> especially the new ones, like the pass-by-value programming style better
> than the pass-by-reference style.

If h1 is an instance of your object, and you type the following:

h2 = h1;

do you want h2 to "point to" or control the same plot as h1? If so, you
want h1 to be a handle, just like a1 and a2 in the following snippet are
handles to the same axes:

a1 = axes;
a2 = a1;

--
Steve Lord
slord@mathworks.com

Subject: I want to make a handle/pointer to a non-handle dataset...

From: Ken Fuller

Date: 22 Jun, 2009 00:33:01

Message: 3 of 4

"Steven Lord" <slord@mathworks.com> wrote in message <h0r2m3$3fq$1@fred.mathworks.com>...
>
> "Ken Fuller" <kfuller5@juno.com> wrote in message
> news:h0q5kv$bqh$1@fred.mathworks.com...
> >I have a question that has been bugging me (he he he) a long time.
> >
> > Why doesn't matlab have some kind of ability to make a pointer/handle to a
> > non-handle dataset?
> >
> >
> > What I want to do is to save a pointer of an object in a GUI using the
> > GUIDATA function, but I don't want the original object to be of the handle
> > class.
> >
> > Specifically, I made a class that has some methods that create some plots.
> > I want the
> > plots to be able to update in both directions. Ie if the user adds data
> > to the object,
> > the plots update, or if the user changes the plot itself, the data in the
> > object will
> > update. To make the object update the plot is easy. To make the plot
> > update the object, without the object being inherited as a handle class,
> > is hard. The reason it's hard is because any reference I put into the GUI
> > is a copy of the object, not a link to the original.
>
> So from this description of the behavior you want the object to have, you
> _do_ want the object to be a handle object, so that copies are "links" to
> the original.
>
> > Oh yeah, I don't want the object to be a handle class because some users,
> > especially the new ones, like the pass-by-value programming style better
> > than the pass-by-reference style.
>
> If h1 is an instance of your object, and you type the following:
>
> h2 = h1;
>
> do you want h2 to "point to" or control the same plot as h1? If so, you
> want h1 to be a handle, just like a1 and a2 in the following snippet are
> handles to the same axes:
>
> a1 = axes;
> a2 = a1;
>
> --
> Steve Lord
> slord@mathworks.com
>

Let me use a simple pointer example of what I am ultimately trying to do.

Lets say I do this:

x=rand(4,4);

And I make a simple function:

function [A]=myfunc(x)

A=x+1;

end

Now I run the function:
z=myfunc(x);

When the function runs, internal to the function, a copy of A is made. When the value is returned, we have two unique sets of data, x & z. What I'd like to do is pass in a pointer of the x variable to the myfunc, and have it do it's operations on x directly. So, when z is returned from the function, it is just another pointer to x.

This particular case is pretty trivial, but if the datasets are large, RAM can be unneccessarily used. I wish that I could treat the x object as a handle, even though it is a double. If matlab would allow me to make a handle to it, like it allows me to make a handle to a function, that would work-out nicely.

x=rand(4,4);

But now I want to say something like:
b=@x;

and run the function again, but slightly different:
myfunc(b);

I'd still like the x variable to be added to one.

As far as I know, matlab doesn't allow for pointers/handles to a non-handle dataset to exist. Thereby, I can't do what I want to do.

Subject: I want to make a handle/pointer to a non-handle dataset...

From: Christopher Creutzig

Date: 23 Jun, 2009 14:26:11

Message: 4 of 4

Ken Fuller wrote:

> When the function runs, internal to the function, a copy of A is made. When the value is returned, we have two unique sets of data, x & z. What I'd like to do is pass in a pointer of the x variable to the myfunc, and have it do it's operations on x directly. So, when z is returned from the function, it is just another pointer to x.

 I guess you are looking for this:
http://blogs.mathworks.com/loren/2007/03/22/in-place-operations-on-data/


Christopher

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
handle Ken Fuller 11 Jun, 2009 01:49:05
function handle Ken Fuller 11 Jun, 2009 01:49:05
objects Ken Fuller 11 Jun, 2009 01:49:05
gui Ken Fuller 11 Jun, 2009 01:49:05
rssFeed for this Thread

Contact us at files@mathworks.com