Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
mmenvo
mmenvo le 1 Nov 2012
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?

Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 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 commentaire
mmenvo
mmenvo le 1 Nov 2012
Modifié(e) : mmenvo le 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);

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Data Type Conversion dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by