using regexp for char data
11 次查看(过去 30 天)
显示 更早的评论
out1 =
p.11 109 820 109
p.12 503 159 117
p.13 234 207 151
p.14 139 134 215
Name Size Bytes Class Attributes
out1 1x188 376 char global
%when I want to exctract first column of this data I use
out1 = char(regexp(out1,'p\.\d+','match'))
%the problem is first column characters varies. for example out1 would be;
out1 =
o10 109 820 109
o12 503 159 117
o13 234 207 151
o14 139 134 215
%or it would be
out1 =
oa10 109 820 109
ob12 503 159 117
oc13 234 207 151
od14 139 134 215
%as you seen, it changes so I need to use regexp without dependent first character or numbers belongs to first column.
thanks in advance
0 个评论
回答(1 个)
Azzi Abdelmalek
2013-7-10
a=cellfun(@(x) regexp(x,'\d+','match'),out1,'un',0);
for k=1:numel(a)
out(k,1)=str2num(char(a{k}(1)))
end
3 个评论
Jan
2013-7-10
It seems like out1 is a string, which contain line breaks: "1x188 char". Do you assume it is a cell string.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!