String starting with letter 's' from cell array

7 visualizaciones (últimos 30 días)
Gopalakrishnan venkatesan
Gopalakrishnan venkatesan el 17 de Ag. de 2015
Respondida: Guillaume el 17 de Ag. de 2015
I have a cell array a = {'sa_dfa','soft_df1','sock_dd2','saz_dfa_d2','suu_f'}
How to extract only the string starting with letter 's' but need to exclude the string starting with soft and sock
so a = {'sa_dfa',[],[],'saz_dfa_d2','suu_f'}
How can I do this?
Thanks a lot

Respuesta aceptada

Guillaume
Guillaume el 17 de Ag. de 2015
As per Stalin's answer you can use strncmp and related with logical operators:
a(strncmp(a, 's', 1) & ~strncmp(a, 'sock', numel('sock')) & ~strncmp(a, 'soft', numel(sock)))
Or you can use a regular expression:
a(~cellfun(@isempty, regexp(a, '^s(?!ock|oft)')))
The above regular expression matches any string that starts with 's' not followed by 'ock' or 'oft'.

Más respuestas (0)

Categorías

Más información sobre Characters and Strings 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