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 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