How to get rid of unwanted comment in the data imported using 'readtable'
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (2)
Mukul Rao
le 5 Déc 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 commentaires
Peter Perkins
le 19 Déc 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 commentaires
Voir également
Catégories
En savoir plus sur Data Type Conversion dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!