Function definitions are not permitted in this context when using arrayfun in matlab

时间:2015-06-30 13:41:11

标签: matlab

I have the following code to create 100 networks. Each network corresponds to a directory. For each directory, i.e., for each network, we call the function arrayfun to sample a fraction of the nodes of the given network, (since we need to do this a number of times, so here we use the function arrayfun). Now, when I run this code, I got the error, saying that the function definitions are not permitted in this context with respect to arrayfun. Can anyone tell me what is wrong with this code? Moreover, is there any better way to do this instead of the arrayfun? Many thanks.

clear;
global seq_len
global dir_name
seq_len =100;
[X,Y] = meshgrid( 0 : seq_len-1, 0 : seq_len-1 );
dst_mtr = abs( Y-X );
dst_mtr = arrayfun( @get_distance, dst_mtr)
k = randperm(seq_len);
fraction_vec = 0.9 : -0.1 :0;
n_smpled_nodes_vec = round (fraction_vec * seq_len);
n_networks = 200;

for i=1:n_networks % i is the currendt network label
    dir_name = strcat ('network', num2str(i));
    mkdir (dir_name);
    arrayfun(@get_sampling, n_smpled_nodes_vec);
end

0 个答案:

没有答案