How to take first character of Alphabet

6 visualizaciones (últimos 30 días)
Mekala balaji
Mekala balaji el 5 de Abr. de 2018
Editada: M el 5 de Abr. de 2018
Hi,
I want to take the first character of the first alphabet from string contain mixed data,
I have below cell array:
data:
{'VA00K100E4TOO';'ZVA00K100E4TOO';'VZA00K100E6TO';'VB00K100E4TOO';'VP00K50E4T4O';'ZVG00K100E4TOO';'VF00K40E4T5O'}
1. I want to first letter of alphabet, ignore if first or second characters are Z or V.
I use below command to extract alphabets from each string,
data(isstrprop(data,'alpha'))
but later I am unable to avoid if the first or second character is Z or V,
my desired output:
A
A
A
B
P
G
F

Respuestas (1)

M
M el 5 de Abr. de 2018
Editada: M el 5 de Abr. de 2018
One way to do it :
regexpi(data,'[a-u]','match','once')
ans =
7×1 cell array
{'A'}
{'A'}
{'A'}
{'B'}
{'P'}
{'G'}
{'F'}
  2 comentarios
Mekala balaji
Mekala balaji el 5 de Abr. de 2018
Sir,
it works,but may I know how does it work? if I want avoide other alphabets (like if first or second letter is N or T etc), and the very first alphabet,
M
M el 5 de Abr. de 2018
Editada: M el 5 de Abr. de 2018
To write a more generic version of my previous answer, you can use something like:
Alphabet = '[ABCDEFGHIJKLMNOPQRSTUVWXYZ]';
% choose which letters you want to suppress
lettersToRemove=['Z' 'V'];
% remove them from your alphabet list:
for i=1:numel(lettersToRemove)
Alphabet(Alphabet==lettersToRemove(i))=[];
end
% keep only the first letter of your alphabet list:
regexpi(data,Alphabet,'match','once')
ans =
7×1 cell array
{'A'}
{'A'}
{'A'}
{'B'}
{'P'}
{'G'}
{'F'}
% Now, suppose you want to remove V and G:
lettersToRemove=['V' 'G'];
for i=1:numel(lettersToRemove)
Alphabet(Alphabet==lettersToRemove(i))=[];
end
regexpi(data,Alphabet,'match','once')

Iniciar sesión para comentar.

Categorías

Más información sobre Startup and Shutdown 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!

Translated by