regexp usage for cellArray data which includes both characters and numbers.
8 ビュー (過去 30 日間)
古いコメントを表示
cellArray=cellstr(cellArray)
cellArray =
'O2930202 465254.432 4066809.025'
'O2910008 499252.083 4042876.84'
'O2920014 494404.625 4047958.526'
Name Size Bytes Class Attributes
cellArray 22x1 4236 cell
%when I want to extract first column of the cellArray, I use
out1 = regexp(cellArray,'(?<=^\s*)\d*','match')
out1 = cat(1,out1{:})
out1 = sprintf('%s\n', out1{:})
%but it doesn't work because there are characters with numbers. It only works if only numbers are exist.
%what kind of code I need to write for extracting first column in terms of both characters and numbers.
0 件のコメント
採用された回答
Andrei Bobrov
2013 年 7 月 10 日
cellArray ={'O2930202 465254.432 4066809.025';
'O2910008 499252.083 4042876.84';
'O2920014 494404.625 4047958.526'}
out1 = regexp(cellArray,'(^[a-zA-Z]*)|((?<=^\w*)\d*)','match');
out = cat(1,out1{:});
0 件のコメント
その他の回答 (1 件)
Jim Hokanson
2013 年 7 月 10 日
Try not to use lookaround operators in Matlab.
If you only want the first column:
first_column_string = regexp(cellArray,'\d+','match','once')
first_column_numbers = str2double(first_column_string)
The key is using 'once' ...
If your input was a single string you could use textscan:
str = strjoin(cellArray','\n') %2013a?
or
temp = strcat(cellArray,{char(10)});
str = [temp{:}];
data = textscan(str,'O%f %f %f','MultipleDelimsAsOne',true);
first_column_numbers = data{1}
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Cell Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!