Tuesday, 15 September 2015

MATLAB : Get k random subscripts with condition from a Matrix -



MATLAB : Get k random subscripts with condition from a Matrix -

i'd k random subscripts a used in c++ programme load info file given set of subscripts.

i've mxn matrix a double values , mx1 matrix b integers 0 20.

how k random subscripts a status b ? in example, given:

a = [ 0.25 0.25 0.25 0.25 0.18 0.18 0.18 0.18 0.36 0.36 0.36 0.36 0.51 0.51 0.51 0.51 ] b = [ 0 1 2 1 ]

i'm trying k = 1 random row subscript i a if b(i) == 1. so, i'm looking i == 1 or i == 4.

i've tried first create logical index as:

idx = b == 1;

and then, a elements status follow:

r = a( idx, : );

and finally, permutation in r in order k rows:

randperm( size(r) )

but i'm stuck not know how translate permutation matrix a.

i'm trying understand function [i,j] = ind2sub(siz,ind) no thought right how bring together subscripts randon permutation. moreover, results of randperm( size(r) ) related size of r.

so, how k random subscripts a status b ? thought utilize subscripts in c++ programme input parameters

you can relevant row numbers follows:

nrs=1:length(idx); nrs=nrs(idx);

now permute them:

nrs_permidx = randperm(length(nrs)) permuted = nrs(nrs_permidx)

and guess can take here.

matlab random indexing

No comments:

Post a Comment