how to obtain random vector from the defined matrix

3 views (last 30 days)
suppose, for c matrix c=[1 2 3; 3 4 5;6 7 8;9 10 11;12 13 14;15 16 17];
randomly i have to select any row vector.

Accepted Answer

KSSV
KSSV on 22 Nov 2021
c=[1 2 3; 3 4 5;6 7 8;9 10 11;12 13 14;15 16 17];
[m,n] = size(c)
m = 6
n = 3
idx = randsample(m,1)
idx = 3
iwant = c(idx,:)
iwant = 1×3
6 7 8

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices 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!