필터 지우기
필터 지우기

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

조회 수: 2 (최근 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에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by