How to get rid of unwanted comment in the data imported using 'readtable'
2 ビュー (過去 30 日間)
古いコメントを表示
I want to import some tide data into MATLAB, however the data I imported is not pure number, some of them have a letter following the number, but I only need the number, is there anyway to get rid of letters?? thanks!!
<<
>>
0 件のコメント
回答 (2 件)
Mukul Rao
2017 年 12 月 5 日
Hello, if each element "sealevel" is a character array, you could use the " regexp " function to filter out those indices that correspond to elements that match a certain regular expression.
Here is an example
>> cellArray = {'1.487','8.487M','9.487','8.487M'};
>> regExpResult = regexp(cellArray,'\d\.\d{3}M');
>> cellfun(@(in) ~isempty(in),regExpResult)
ans =
1×4 logical array
0 1 0 1
You can substitute "sealevel" for the "cellArray" variable and customize the regular expression further as needed.
0 件のコメント
Peter Perkins
2017 年 12 月 19 日
That's not a table, it's a cell array of ... char row vectors? Hard to know without more info. If it is, then just use strrep and str2double":
>> C = {'1';'2';'3M';'4M'};
>> str2double(strrep(C,'M',''))
ans =
1
2
3
4
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!