How to get rid of unwanted comment in the data imported using 'readtable'
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (2)
Mukul Rao
am 5 Dez. 2017
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 Kommentare
Peter Perkins
am 19 Dez. 2017
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 Kommentare
Siehe auch
Kategorien
Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!