Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

How can I read certain data from my text file?

조회 수: 1 (최근 30일)
Jesus Marcial
Jesus Marcial 2019년 2월 22일
마감: MATLAB Answer Bot 2021년 8월 20일
I have a text file that is formatted as such:
P_527=20024 -568251 0 0, 5908.191819 MHz
P_528=15789 -565446 0 0, 5910.010001 MHz
P_529=10575 -562629 0 0, 5911.828182 MHz
P_530=5744 -561325 0 0, 5913.646364 MHz
I need to read the first column into a vector without the " P_XXX= ", the entire second column, and the final column without the 'MHz'. I've successfully read the second column using textscan but cannot successfully read any of the other columns. Thank you for your help.

답변 (1개)

Walter Roberson
Walter Roberson 2019년 2월 22일
filename = 'test.txt';
fid = fopen(filename);
data = cell2mat(textscan(fid, '%*[^=]=%f %f %*f %*f, %f MHz'));
fclose(fid);

Community Treasure Hunt

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

Start Hunting!

Translated by