How to take first character of Alphabet

6 vues (au cours des 30 derniers jours)
Mekala balaji
Mekala balaji le 5 Avr 2018
Modifié(e) : M le 5 Avr 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

Réponses (1)

M
M le 5 Avr 2018
Modifié(e) : M le 5 Avr 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 commentaires
Mekala balaji
Mekala balaji le 5 Avr 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 le 5 Avr 2018
Modifié(e) : M le 5 Avr 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')

Connectez-vous pour commenter.

Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by