select a random number from each row in a matrix with changable columns

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)

rows = 256 ;
cols = randsample(rows,1) ;
A = rand(rows,cols) ;
% Select a row randomly
idx = randsample(rows,1) ;
A(idx,:)

2 Comments

thanks , but i want to select one number from each row
Okay..you can do that...use randsample.

Sign in to comment.

Categories

Find more on Random Number Generation in Help Center and File Exchange

Asked:

on 7 Mar 2019

Answered:

on 7 Mar 2019

Community Treasure Hunt

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

Start Hunting!