Find string corresponding to another string within a text file

1 次查看(过去 30 天)
Hi,
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'));

采纳的回答

Mohammad Sami
Mohammad Sami 2020-7-17
编辑:Mohammad Sami 2020-7-17
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');

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 String Parsing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by