|
"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.
|