Find nonzero elements in 5x5 matrix (diagonal, vertical, horizontal line)

3 ビュー (過去 30 日間)
Benjamin Nienhouse
Benjamin Nienhouse 2020 年 10 月 23 日
コメント済み: Benjamin Nienhouse 2020 年 10 月 23 日
Hey,
So I'm wondering how to find a string 5 numbers long in a 5x5 matrix.
I'm trying to code a bingo game and my idea is whenever a number [1-100] is called that is also in my "bingo card" (5x5 matix A) to move that value and corrisponding position into another 5x5 matrix (B) of zeros. How can I find when there is a sting 5 numbers (nonzeros, from A) in a diagonal, vertical, or horizontal line.
Any help or advice is much appreaciated.
Thanks,
Ben.

採用された回答

Matt J
Matt J 2020 年 10 月 23 日
編集済み: Matt J 2020 年 10 月 23 日
For example, to search for a column string,
A =[
1 4 4 4 5
3 1 4 1 4
5 5 2 2 2
4 5 4 1 5
5 4 1 1 1];
all(A==[4;1;5;5;4],1)
ans = 1x5 logical array
0 1 0 0 0

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeConway's Game of Life についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by