Effacer les filtres
Effacer les filtres

how to store parts of one string into a string array??

1 vue (au cours des 30 derniers jours)
Kishore
Kishore le 16 Juil 2014
Commenté : Kishore le 16 Juil 2014
i have a string .i have to identify some specified format in that string and store the identified patterns in another string array. i used to regexp to do that...
but the problem is that i couldn't store the obtained pattern in a string array.
this is the code i developed ......... can anyone help me with this problem??
string='C12C3C4C1C5C4C3C25';
pattern1='([A-Z]\d{1,1}[A-Z|#()=:])';%to identify x1y format
pattern2='([A-Z]\d{2})';%to identify x12y format
pmat1= regexp(string,pattern1, 'match');
pmat2= regexp(string,pattern2, 'match');
for i=1:length(pmat1)
r=pmat1{i:i};
mat=r;
end

Réponse acceptée

per isakson
per isakson le 16 Juil 2014
Try this
string='C12C3C4C1C5C4C3C25';
pattern1='([A-Z]\d{1,1}[A-Z|#()=:])';%to identify x1y format
pattern2='([A-Z]\d{2})';%to identify x12y format
pmat1= regexp(string,pattern1, 'match');
pmat2= regexp(string,pattern2, 'match');
cac = cell( length(pmat1), 1 );
for i=1:length(pmat1)
r=pmat1{i:i};
cac{i}=r;
end
mat = cell2mat( cac );
or replace
cac = cell( length(pmat1), 1 );
by
cac = cell( 1, length(pmat1) );

Plus de réponses (0)

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by