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

采纳的回答

Image Analyst
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)

更多回答(1 个)

rifat
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
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
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 CenterFile Exchange 中查找有关 Linear Least Squares 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by