How can I select a random element in a row of matrix?

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

you create is not resolved. I want to appear in one of two drainage Heat 6-8.
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);

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

태그

질문:

2014년 5월 27일

댓글:

2015년 11월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by