Please help write a script to display the first line of this text file using fgetl

조회 수: 9 (최근 30일)
I am very new to matlab so please explain it assuming I don't know very much about it. Thanks in advance. Here is the first few lines of the text file, I would like "Header Lines = 15" to be displayed. It would also be great if you could show me how to pull up other specific lines in the file!
Header Lines = 15
Tilt Illusion Experiment
Subject Number = 1
Target Contrast = 0.50
Flanker Contrast = 0.50

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 3월 27일
fid=fopen('yourfile.txt')
line=fgetl(fid)
fclose(fid)

추가 답변 (1개)

Jacob Halbrooks
Jacob Halbrooks 2014년 3월 27일
편집: Jacob Halbrooks 2014년 3월 27일
You just need to use FOPEN to create a file handle, and then each call to FGETL on that handle will read a line of text. Here's code that will keep calling FGETL until the end of the file is reached:
fid = fopen('myfile.txt','r');
while ~feof(fid)
line = fgetl(fid);
disp(line);
end
fclose(fid);
Be sure to call FCLOSE when you are done with the file.
  댓글 수: 1
Steve
Steve 2014년 3월 27일
Thanks! I understand the code which is great. I need to only display the first line, what would the code be for that?

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

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by