Filter löschen
Filter löschen

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

2 Ansichten (letzte 30 Tage)
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?

Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 1 Nov. 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 Kommentar
mmenvo
mmenvo am 1 Nov. 2012
Bearbeitet: mmenvo am 1 Nov. 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);

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by