Read from and make new based on positions

1 visualización (últimos 30 días)
Nicle Davidson
Nicle Davidson el 16 de Oct. de 2021
Comentada: Nicle Davidson el 16 de Oct. de 2021
I would like to go through a matrix which looks like this:
the numbers stand for ascii values
where there is capital letter means a word ends.
I read this matrix from a file,
Then I would like to make a new matrix where I register where in this matrix I have the capital words.
So far I know to read from a matrix I would need a for loop such as:
for i=size(S)
%here I would like to make a new matrxi based on the positons of the
%capital words in S matrix
if S(i,j)>=65 || S(i,j)<=90
% here M would form
end
end
but what I actually would like to make out of the S, which is the matrix read from the file and shown above,
is to make a new matrix, say M, which has registerted where I have capital letters in S.
Then M will look like
M=(4 5
5 7
5 10
2 12)
because for example S(4,5) has 87 which stands for the capital letter W.
Questions in background to think about could be:
how can I read from S and make M?
How can I find the positions and use them making a new matrix. If it helps the attached file contains the matrix.

Respuesta aceptada

Ive J
Ive J el 16 de Oct. de 2021
Why not this?
G = [0 115 0 0 0 0 0 0 0 0 111 0 0
0 0 110 0 0 0 110 0 0 0 0 82 0
0 0 0 111 0 0 0 111 0 0 0 0 0
0 0 0 0 87 114 0 0 114 0 0 0 0
0 0 0 0 0 0 84 0 0 84 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0];
idx = G >= 65 & G <= 90;
[r, c] = find(idx);
M = [r, c]
M = 4×2
4 5 5 7 5 10 2 12

Más respuestas (0)

Categorías

Más información sobre Cell Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by