Filter löschen
Filter löschen

Find string corresponding to another string within a text file

1 Ansicht (letzte 30 Tage)
I have a text file,
I was trying to read the latitide, longitude and station name corresponding to the associated strings within a text file. For example for reading the latitude and longitude in the file, the below lines worked.
buffer = fileread(fullFileName) ;
lat=str2double(regexpi(buffer, '(?<=Station latitude:\s+) [\d\.]+', 'match'));
lon=str2double(regexpi(buffer, '(?<=Station longitude:\s+) [\d\.]+', 'match'));
However, for station name which is in the .txt file (attached) as Station name: Payerne,
the below line did not work and I am getting NaN as output
name=str2double(regexpi(buffer, '(?<=Station name:\s+) \w*', 'match'));

Akzeptierte Antwort

Mohammad Sami
Mohammad Sami am 17 Jul. 2020
Bearbeitet: Mohammad Sami am 17 Jul. 2020
Station name is a char / string. however you are using str2double. This will ofcourse give you a nan output.
You can remove the str2double.
name=regexpi(buffer, '(?<=Station name:\s+)\w*', 'match');

Weitere Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by