From: Geert Stevens on
Hello,

I need to put some labels at axes and control their visibility state. Below are some basic question about speeding up the itteration/vectorising the process.

i.e. Following code makes the labels and putts them in a cell.
-------
x=0; y=0; num_forces=5;
lbs_forces = cell(1, num_forces);
for i=1:num_forces,
if(1)
lbs_forces{i} = text(x+i,y,['Test', num2str(i)]);
end
end
-------
I'm using lbs_forces as a cell, because I want to control the object properties of all the objects in that cell at 1 time.

I know I could do the following, but I read about vectorizing as the fastest way for matlab.
-------
for m=1:num_forces,
set(lbs_forces{m}, 'Visible', 'off')
end
-------
So I tried something like this:
-------
set(lbs_forces{:}, 'Visible', 'off')
-------
But this won't work, why is this? Also, is there a way to speed up the first mentioned for loop?


Thanks in advance,
Geert
From: Joachim Vandekerckhove on
On Sun, 2010-05-16 at 22:36 +0000, Geert Stevens wrote:
> Hello,
>
> I need to put some labels at axes and control their visibility state. Below are some basic question about speeding up the itteration/vectorising the process.
>
> i.e. Following code makes the labels and putts them in a cell.
> -------
> x=0; y=0; num_forces=5;
> lbs_forces = cell(1, num_forces);
> for i=1:num_forces,
> if(1)
> lbs_forces{i} = text(x+i,y,['Test', num2str(i)]);
> end
> end
> -------
> I'm using lbs_forces as a cell, because I want to control the object properties of all the objects in that cell at 1 time.
>
> I know I could do the following, but I read about vectorizing as the fastest way for matlab.
> -------
> for m=1:num_forces,
> set(lbs_forces{m}, 'Visible', 'off')
> end
> -------
> So I tried something like this:
> -------
> set(lbs_forces{:}, 'Visible', 'off')
> -------
> But this won't work, why is this? Also, is there a way to speed up the first mentioned for loop?
>
>
> Thanks in advance,
> Geert

A handle to a label is just a number. Using a normal double array
lbs_forces() instead of a cell lbs_forces{} should work.

hth

From: Geert Stevens on
Joachim Vandekerckhove <joachim.vandekerckhove(a)gmail.com> wrote in message <1274051639.3731.1.camel(a)Winky>...
> On Sun, 2010-05-16 at 22:36 +0000, Geert Stevens wrote:
> > Hello,
> >
> > I need to put some labels at axes and control their visibility state. Below are some basic question about speeding up the itteration/vectorising the process.
> >
> > i.e. Following code makes the labels and putts them in a cell.
> > -------
> > x=0; y=0; num_forces=5;
> > lbs_forces = cell(1, num_forces);
> > for i=1:num_forces,
> > if(1)
> > lbs_forces{i} = text(x+i,y,['Test', num2str(i)]);
> > end
> > end
> > -------
> > I'm using lbs_forces as a cell, because I want to control the object properties of all the objects in that cell at 1 time.
> >
> > I know I could do the following, but I read about vectorizing as the fastest way for matlab.
> > -------
> > for m=1:num_forces,
> > set(lbs_forces{m}, 'Visible', 'off')
> > end
> > -------
> > So I tried something like this:
> > -------
> > set(lbs_forces{:}, 'Visible', 'off')
> > -------
> > But this won't work, why is this? Also, is there a way to speed up the first mentioned for loop?
> >
> >
> > Thanks in advance,
> > Geert
>
> A handle to a label is just a number. Using a normal double array
> lbs_forces() instead of a cell lbs_forces{} should work.
>
> hth

Thanks, this solves the problem. I didn't know that the handle was just a number, although the workspace clearly indicates it.