"stinkinrich88" <stinkinrich88@gmail.com> wrote in message <hcrq0q$ast$1@fred.mathworks.com>...
> Hello,
>
> I have the following code in my program:
>
> for i_node = 1 : n_node
> point_array(i_node, :, :) = mob_model(n_dim, n_step);
> end
>
> The function mob_model returns a trajectory (array of positions) of a single node. n_dim says how many dimensions the region has and n_steps says how many timesteps to generate positions for. i.e. mob_model returns an array of size n_dim x n_step.
>
> This is done for n_node nodes using the for loop. But surely there is a way to avoid this for loop? I was hoping for something like:
>
> point_array(1 : n_node, :, :) = mob_model(n_dim, n_step);
>
> But it doesn't work. I think it would be good practice to keep mob_model returning a single trajectory, but maybe I'm wrong.
>
> Any ideas? Thanks.
> Rich
If I understood you post correctly, mob_model(C1,C2) will return a semirandom matrix of a particular size. That is, each time it is called it will give a different result.
If that is the case, there is no easy way to vectorize it other than:
1) modify the code of "mob_model" to make it vectorized
2) use ARRAYFUN
fh = @(x) rand(2,3) % note that x is not used, like "i_node" above
C = arrayfun(fh,1:3,'un',0)
C = cat(3,C{:}) % concatenate into one array
hth
Jos
