How can i select randomly Boolean number from a array ?

A= 0 0 1 1 0 1
0 0 0 1 1 1
1 0 0 1 0 1
1 1 1 0 1 1
0 1 0 1 0 0
1 1 1 1 0 0
for example how can i select randomly a 1 from a row or a column? as Aij=Aji equal no problem select from row or column

 採用された回答

Wayne King
Wayne King 2013 年 2 月 4 日

2 投票

idx = find(A == 1);
randsamp = randi(length(idx),1,1);
index = idx(randsamp);
% index is the linear index of the randomly choosen 1
% I, J is the row-column index
[I,J] = ind2sub(size(A),index);

その他の回答 (1 件)

Image Analyst
Image Analyst 2013 年 2 月 4 日

0 投票

What are you looking for? You know you'll get a 1 - that's a given. So, if you specify the column, do you want the row number? And if you specify a row, do you want the column number?

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by