Finding index of a found string inside a string array

Hi there i'm trying to code a polybius square cipher in matlab. I am trying to find the index if the current character in the alphabet string which is a 5*5 string array.
grid = ["A", "B", "C", "D", "E";
"F", "G", "H", "I/J", "K";
"L", "M", "N", "O", "P";
"Q", "R", "S", "T", "U";
"V", "W", "X", "Y", "Z"
];
characterindex = strfind(grid, "letter");
I need character index to return an index rather than 5*5 cell array so i can find the corrisponding index.
Help would be hugely appreciated,
many thanks

2 件のコメント

Stephen23
Stephen23 2023 年 2 月 21 日
編集済み: Stephen23 2023 年 2 月 21 日
Original question by Rahim Neal Yakoob retrieved from Google Cache:
Finding index of a found string inside a string array
Hi there i'm trying to code a polybius square cipher in matlab. I am trying to find the index if the current character in the alphabet string which is a 5*5 string array.
grid = ["A", "B", "C", "D", "E";
"F", "G", "H", "I/J", "K";
"L", "M", "N", "O", "P";
"Q", "R", "S", "T", "U";
"V", "W", "X", "Y", "Z"
];
characterindex = strfind(grid, "letter");
I need character index to return an index rather than 5*5 cell array so i can find the corrisponding index.
Help would be hugely appreciated,
many thanks
Rena Berman
Rena Berman 2023 年 3 月 9 日
(Answers Dev) Restored edit

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

回答 (1 件)

Walter Roberson
Walter Roberson 2019 年 11 月 7 日

0 投票

[row, col] = find(contains(grid, "letter"));
Caution: this would work even for "/" because that is present in your "I/J" string. The code makes no attempt to be smart about what is stored at the locations.

カテゴリ

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

タグ

質問済み:

2019 年 11 月 7 日

コメント済み:

2023 年 3 月 9 日

Community Treasure Hunt

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

Start Hunting!

Translated by