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

1 次查看(过去 30 天)
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?

采纳的回答

Azzi Abdelmalek
Azzi Abdelmalek 2012-11-1
v={'r1200i000-0ln140010.LID'
'r1200i100-4ln140030.LID'
'r1200i100-8ln140010.LID'
'r1225i100-8ln140030.LID'}
out=cellfun(@(x) str2num(x(14:15)),v,'un',0)
  1 个评论
mmenvo
mmenvo 2012-11-1
编辑:mmenvo 2012-11-1
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);

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Variables 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by