How to read mix characters in a cell, and write to another cell?

1 visualización (últimos 30 días)
In Matlab, I want to read specific characters from a cell which contains a mixture of numbers and texts and write them in a different cell. How can I do that in matlab? Could anybody help me with codes, please.
Here is the example:
-------------------------------------------------------------------------
r1200i000-0ln140010.LID
r1200i100-4ln140030.LID
r1200i100-8ln140010.LID
r1225i100-8ln140030.LID
-------------------------------------------------------------------------
This represents a string in a cell. I have more than such 100000 rows (cells) in a single column. I want to read the 14th and 15 th character (here 14th is 1 and 15th is 4) and write this value in a different column in the same row.
I think this [str2num or str2double] can help because i want to read strings and write the specific characters as numbers.
Could anybody help me how to write the codes for this work, please?

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 1 de Nov. de 2012
v={'r1200i000-0ln140010.LID'
'r1200i100-4ln140030.LID'
'r1200i100-8ln140010.LID'
'r1225i100-8ln140030.LID'}
out=cellfun(@(x) str2num(x(14:15)),v,'un',0)
  1 comentario
mmenvo
mmenvo el 1 de Nov. de 2012
Editada: mmenvo el 1 de Nov. de 2012
Thanks a lot Azzi Abdelmalek. I tried with the help that you provided. Still matlab shows following errors:
??? Error using ==> cellfun
Input #2 expected to be a cell array, was double instead.
I used this code:
--------------------------
modewidth = xlsread('test data.xlsx', 'A2:A165238');
v = modewidth;
out=cellfun(@(x) str2double(x(14:15)),v,'un',0);

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Variables 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