MATLAB: How to parse this given data in matlab

#helpmatlab#parsedataMATLAB

Best Answer

  • S = fileread('YourFileNameGoesHere.txt');
    colon_matches = regexp(S, '^.*:\s*(?<v1>\S+)\s*(?<v2>\S+)', 'dotexceptnewline', 'lineanchors');
    v1 = str2double({colon_matches.v1});
    v2 = str2double({colon_matches.v2});
    power_matches = regexp(S, '^\w+\s+(?<power>)', 'lineanchors');
    p = str2double({power_matches.power});
    header_vals = [v1(:), v2(:)];
    power_vals = p(:);