Docsity

Reading Text Files in Matlab: Formatting and Reading Specific Fields, Lecture notes of Computer Programming

Partial preview of the text

Download Reading Text Files in Matlab: Formatting and Reading Specific Fields and more Lecture notes Computer Programming in PDF only on Docsity!

Matlab

텍스트 파일 읽기 데이터 처리

텍스트 파일 읽기(textread)

[a, b, c] =textread('C:\Users\jycho\Desktop\test.txt', '%u %u %c')

format 지정

  • https://kr.mathworks.com/help/matlab/ref/textread.html 형식 동작 출력값 %d 부호가 있는 정수 값을 읽습니다. double형 배열 %u 정수 값을 읽습니다. double형 배열 %f 부동소수점 값을 읽습니다. double형 배열 %s 공백 또는 구분 기호로 구분된 텍스트를 읽습니다. 문자형 벡터로 구성된 셀형 배열 %q 큰따옴표로 묶인 텍스트를 큰따옴표를 제하고 읽습니다. 문자형 벡터로 구성된 셀형 배열 %c 공백을 포함하여 문자를 읽습니다. 문자형 배열
  • 헤드라인 제거 [a, b, c] =textread( ‘C:\Users\jycho\Desktop\test.txt', '%u %u %c‘, ‘headerlines’,1)
  • 구분자 제거 [a, b, c] =textread( ‘C:\Users\jycho\Desktop\test.txt', '%u %u %c‘, ‘delimiter’, ’,’)

temp=flipud(temp) psu=flipud(psu) yyaxis left plot(temp) yyaxis right plot(psu) legend('temp','psu') [num, kor, eng, mat, com, sci] = textread('score1.txt','%u %u %u %u %u %u','headerlines',1) max_eng=- 1 for (i=1:length(eng)) if max_eng<eng(i) max_eng=eng(i) end end disp(max_eng)