필터 지우기
필터 지우기

I need to use 'for loop' to read the names from a text file using 'fgetl' function. How do I do that?

조회 수: 17 (최근 30일)
There is a list of 80 test subject names in a text file, and I have to use the for loop function to read the names of the first 40 subjects using fgetl function. How do I write the code in MATLAB.
Thanks!!
  댓글 수: 2
anukriti dureha
anukriti dureha 2013년 6월 2일
do u specifically have to use for???... or u can use while loop too?
kiran sai kadiyala
kiran sai kadiyala 2020년 2월 21일
clear all
close all
clc
%importing data
f1=fopen('your_file.dat','r')
%n=no of rows in your file
n=218;
for i=1:n;
ab{i}=fgetl(f1);
end

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

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 6월 2일
편집: Azzi Abdelmalek 2013년 6월 2일
fid = fopen('filename.txt');
line1 = fgetl(fid);
res=line1;
while ischar(line1)
if ischar(line)
res =char(res,line1)
end
line1 = fgetl(fid);
end
fclose(fid);
  댓글 수: 3
Image Analyst
Image Analyst 2013년 6월 2일
Reading the help is always a good idea. In there is this example:
Examples
Read and display the file fgetl.m one line at a time:
fid = fopen('fgetl.m');
tline = fgetl(fid);
while ischar(tline)
disp(tline)
tline = fgetl(fid);
end
fclose(fid);

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

추가 답변 (1개)

anukriti dureha
anukriti dureha 2013년 6월 2일
  댓글 수: 1
Steve88
Steve88 2013년 6월 2일
Thanks for the links dude...the requirement is a for loop....I'll read through the stuff..much appreciated..

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

카테고리

Help CenterFile Exchange에서 Large Files and Big Data에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by