select a random number from each row in a matrix with changable columns
Show older comments
hello, i want to create a matrix with 256 rows and random number of columns then i want to select randomly one number from each row and display all chosen numbers from all rows in one array
Answers (2)
KSSV
on 7 Mar 2019
rows = 256 ;
cols = randsample(rows,1) ;
A = rand(rows,cols) ;
% Select a row randomly
idx = randsample(rows,1) ;
A(idx,:)
madhan ravi
on 7 Mar 2019
arrayfun(@(x)a(x,randi(size(a,2))),1:size(a,1)).' % a your matrix
Categories
Find more on Random Number Generation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!