How can I select a random element in a row of matrix?
1 回表示 (過去 30 日間)
古いコメントを表示
Hello
I want to select a a random element in a row and then I want to know the column of this element
Could you Help me?
Thanks
0 件のコメント
採用された回答
Image Analyst
2014 年 5 月 27 日
Try this:
yourMatrix = magic(9) % Sample data
randomColumnNumber = randi(size(yourMatrix, 2), 1)
row = 3; % Whatever
% Get the value of the matrix at this location.
randomValueInRow = yourMatrix(row, randomColumnNumber)
0 件のコメント
その他の回答 (1 件)
rifat
2014 年 5 月 27 日
Assuming the data is in 'row'
col=1+floor(rand()*length(row)) % column number of the randomly selected element
element=row(col) % randomly selected element
2 件のコメント
Ji-hwan Hwang
2015 年 11 月 29 日
you create is not resolved. I want to appear in one of two drainage Heat 6-8.
Walter Roberson
2015 年 11 月 29 日
Ji-hwan Hwang, I do not understand what you mean by "I want to appear in one of two drainage Heat 6-8" ?
If you want to select randomly from column 6 to 8, then
col = randi([6 8]);
element = row(col);
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!