Clear Filters
Clear Filters

Info

This question is closed. Reopen it to edit or answer.

Read numbers from string by search

1 view (last 30 days)
Toke
Toke on 11 Jul 2013
Closed: MATLAB Answer Bot on 20 Aug 2021
this is a simple problem. I have a string e.g.:
Elevation=34.52;AltTX=30.08;AltTxStd=9.8489e-02;AltLatSTD=3.0000e-01;AltRx=31.09;AltRxStd=9.85e-02;TiltX=264.75;TiltXSTD=1.0038e+00;TiltY=269.75;TiltYSTD=1.0037e+00;FieldPolarity=3;Current=7.560;Dataset=1;DaPositions=2814;SondNo=696;SegNo=1;LineNo=0;AveRes=150;
The string is read from a file I opened by fopen and fgets.
Now, I need to read the number from AltTX out from this string. I guess I have to do a search on 'AltTX=' and then read the next 5 characters. Since the text before and after AltTX can change in length I can not just read the same number of characters from the string. Do I use textscan, strfind or what is an easy solutiion?

Answers (1)

Jan
Jan on 11 Jul 2013
Str = 'Elevation=34.52;AltTX=30.08;AltTxStd=9.8489e-02;'; % Abbrev.
Search = 'AltTX';
Index = strfind(Str, [Search, '=']);
Value = sscanf(Str(Index + (length(Search) + 1):end), '%g', 1);

This question is closed.

Tags

Community Treasure Hunt

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

Start Hunting!