Random array Coordinates for certain elements

If I have an array 397x596 size filled with 1 and 0, is there a method where I could generate a random coordinate of the array that has element of 0?
So far I have used [row, column] = find(house == 0); to find the coordiantes containing 0

 採用された回答

Just Manuel
Just Manuel 2021 年 2 月 17 日

0 投票

Well, you're almost there.
just pick a random pair from row and column
% i'm just generating a random house here
house = rand(397,596) > 0.5;
% your code to find indices of elements that are zero
[row, column] = find(house == 0);
% go ahead and pick one of those indices
n = randi(length(row));
row_coord = row(n);
col_coord = column(n);
Cheers
Manuel

3 件のコメント

Qiabin John Su
Qiabin John Su 2021 年 2 月 17 日
Thanks so much
Just Manuel
Just Manuel 2021 年 2 月 17 日
De nada, señor!
Rik
Rik 2021 年 2 月 17 日
@Just Manuel, regarding your flag ("To be honest, I did not read the community rules yet. Is writing "your welcome" in spanish considered spam? :D"): your comment was caught by the automatic spam detection. As far as I'm aware it is not against the community guidelines. Sometimes the spam detection will have a false positive, I wouldn't read too much into this. Flagging is manual, the spam detection is not. I have now removed the spam marker and your flag.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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

製品

質問済み:

2021 年 2 月 17 日

コメント済み:

Rik
2021 年 2 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by