select random row inside the cell

1 view (last 30 days)
NA on 5 Apr 2019
Edited: Jos (10584) on 5 Apr 2019
choosen_row=cellfun( @(m) datasample( m,number_of_choosen_row,'replace',false ), A, 'uni',false);
I want to chose random row inside a cell. but above code does not give me correct result.
for example result should be choosen_row={[3],[1],[1]}

Accepted Answer

Jos (10584)
Jos (10584) on 5 Apr 2019
Edited: Jos (10584) on 5 Apr 2019
You want the row, or the row number to be returned?
rownumber = cellfun(@(c) randperm(size(c, 1), 1), A)
row = cellfun(@(c) c(randperm(size(c, 1), 1), :), A, 'un', 0)

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!