How can I randomly select a row from a matrix?
5 ビュー (過去 30 日間)
古いコメントを表示
I have a matrix (m) that is 17543 x 17. The values are of the type double.
I want to randomly select 1 row from this matrix and save it as a new vector.
I tried this:
mrow = m(randsample(m:17543,1),:)
This works if the values are integers but it does not work because they are doubles.
It returns the error message:
"Subscript indices must either be real positive integers or logicals."
Any help would be really appreciated.
Thanks,
Graeme
1 件のコメント
chaitra kn
2019 年 8 月 17 日
this is for to select only first row,how can i select more than one random rows in two 2 matrix.
please help me out
採用された回答
Evan
2013 年 6 月 17 日
編集済み: Evan
2013 年 6 月 17 日
Try this:
ind = ceil(rand * size(m,1));
mrow = m(ind,:);
5 件のコメント
Sushmita kumari
2022 年 2 月 11 日
i i wish to find a coloum insted of row .please suggest sutable code
その他の回答 (2 件)
Wayne King
2013 年 6 月 17 日
編集済み: Wayne King
2013 年 6 月 17 日
m = randn(17543,17);
idx = randperm(size(m,1),1);
B = m(idx,:);
idx tells you which row you randomly selected.
If you have an older version of MATLAB where the above does not work do:
m = randn(17543,17);
idx = randperm(size(m,1),1);
B = m(idx(1),:);
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!