replace first elements from 1 col to numbers
2 次查看(过去 30 天)
显示 更早的评论
Hi, I have 26x1 cell matrix
s= {'O363'
'O321'
'null'
'O800'
'O411'
'O342'
'O820'
'O244'
'O13'
'O300'
'O623'
'O601'
'Z311'
'Z372'
'O811'
'Q738'
'O142'
'E039'
'B951'
'O64'
'G40'
'O11'
'E669'
'E059'
'I519'
'D65'
'O800'
'O411'
}
I want to replace first chars with numbers as:
s1 = [10363
10321
0
10800
10411
10342
10820
10244
1013
10300
10363
10601
11311
11372
10811
12738
10142
13039
14951
1064
1540
1011
13669
13059
16519
1765
10800
10411]
采纳的回答
Stephen23
2016-2-17
编辑:Stephen23
2016-2-17
chr = 'BDEFGHIJOPQZ';
num = 10+(0:numel(chr)-1);
org = strcat('^',[{'null'};num2cell(chr(:))]);
rep = [{'0'};cellstr(num2str(num(:)))];
out = regexprep(s,org,rep);
Gives strings in a cell array:
18363
18321
0
18800
18411
18342
18820
... more here
18800
18411
Note that this encoding follows the one that you gave in your comment, not the one in your original question.
4 个评论
Stephen23
2016-2-17
编辑:Stephen23
2016-2-17
str2double(out)
If that does not work then you actually need to give us more information than "It seems there is an error.", because we cannot read your computer screen and we cannot read your mind. If you tell us the complete error message and show the code you are using then we can help you.
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!