Not all cell converte to double

Hello. I don't know how to convert cell to double and cut part of cell. This is my list:
list={'6.txt' '13.txt' '14.txt' '19.txt' '45.txt' '53.txt'};
and I need it without '.txt'.
Thanks in advance for any help.

 Respuesta aceptada

dpb
dpb el 27 de Ag. de 2013
>> sscanf([list{:}],'%d.txt')
ans =
6
13
14
19
45
53
>>

2 comentarios

Jan
Jan el 28 de Ag. de 2013
This is surprisingly fast even for large cell strings. A further speedup can be achieved by using FEX: CStr2String, which seems to perform a better pre-allocation of the output:
sscanf(CStr2String(list), '%d.txt');
dpb
dpb el 28 de Ag. de 2013
I'm not sure why you think decent performance herein is surprising, Jan? I'd think this would be pretty much expected...

Iniciar sesión para comentar.

Más respuestas (2)

Walter Roberson
Walter Roberson el 27 de Ag. de 2013

0 votos

cellfun( @(s) sscanf(s, '%d'), list)

1 comentario

dpb
dpb el 27 de Ag. de 2013
Editada: dpb el 28 de Ag. de 2013
That's good side effect w/ cellfun in this case--the error on the '.txt' portion of the input string goes silently away w/o writing the explicit format string, Walter. I took the other way out to avoid the anonymous function definition but in production yours is probably preferable.

Iniciar sesión para comentar.

Azzi Abdelmalek
Azzi Abdelmalek el 27 de Ag. de 2013
Editada: Azzi Abdelmalek el 27 de Ag. de 2013

0 votos

list=str2double(strrep(list,'.txt',''))

Etiquetas

Preguntada:

el 27 de Ag. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by