how to obtain random vector from the defined matrix

2 views (last 30 days)
Anita Zade
Anita Zade on 22 Nov 2021
Commented: Anita Zade on 22 Nov 2021
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)

Community Treasure Hunt

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

Start Hunting!