Matlab Read .txt files

조회 수: 2 (최근 30일)
sko
sko 2021년 5월 6일
댓글: sko 2021년 5월 6일
Hello,
I have a Matlab txt file containing lines that I want to read as number but also the lines I want to read as text. For instance, my .txt file reads:
8
6
01
02
I need those "values" and for importing those in my code, I used importdata built in function. However, Matlab recognizes the third line of .txt file as 1 (number) and not as 01 (string).
How can I force Matlab to give me the string '01' and '02' in the 3rd and 4th row of txt file?
Thank you in advance
  댓글 수: 3
Walter Roberson
Walter Roberson 2021년 5월 6일
If you are using a new enough release, use readlines() and then str2double() indexing with appropriate indices of lines you want to consider numeric.
sko
sko 2021년 5월 6일
This works perfectly for me!
Thank you

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by