Find string corresponding to another string within a text file

1 回表示 (過去 30 日間)
SChow
SChow 2020 年 7 月 16 日
編集済み: Mohammad Sami 2020 年 7 月 17 日
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 Center および File ExchangeString Parsing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by