Finding index of a found string inside a string array
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Stephen23
el 21 de Feb. de 2023
Editada: Stephen23
el 21 de Feb. de 2023
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
Respuestas (1)
Walter Roberson
el 7 de Nov. de 2019
[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.
0 comentarios
Ver también
Categorías
Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!