From: Frank on
In the interest of speed I like to initialize all of my vectors before they are constructed in loops to avoid having them grow on each iteration.

My usual is to just create the vector before the loop as assign the value zeros(expected size) to it, and then inside the loop stick the real values in the appropriate places.

When I try to do this with a vector of handles I get an error because I can't plug a handle into a vector that has double values. I've found a couple unpleasant ways around this:
example
variable = handle;
variable(expected_size) = handle;

which will give me a vector of the appropriate size that will accept handle values, but I'd like a better way of doing this.

I appreciate the help,

Frank
From: us on
"Frank " <fshavlak(a)gmail.com> wrote in message <hkcdt4$lfq$1(a)fred.mathworks.com>...
> In the interest of speed I like to initialize all of my vectors before they are constructed in loops to avoid having them grow on each iteration.
>
> My usual is to just create the vector before the loop as assign the value zeros(expected size) to it, and then inside the loop stick the real values in the appropriate places.
>
> When I try to do this with a vector of handles I get an error because I can't plug a handle into a vector that has double values. I've found a couple unpleasant ways around this:
> example
> variable = handle;
> variable(expected_size) = handle;
>
> which will give me a vector of the appropriate size that will accept handle values, but I'd like a better way of doing this.
>
> I appreciate the help,
>
> Frank

one of the solutions (iff i understand the problem correctly)...

clear hv;
hv(2,2)=handle(figure)
%{
% hv =
handle: 2-by-2
%}
hv(1,1)=handle(axes);
ishandle(hv)
%{
1 0
0 1
%}

us
From: Matt Fig on
I guess I don't see the problem. Are you saying that this errors on your setup?


>> clear all
>> h = zeros(1,3);
>> h(1) = handle(figure);
>> h(2) = handle(axes);
>> h(3) = handle(uicontrol)

h =

1 157.003051757813 158.003051757813