フィルターのクリア

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 Center および File ExchangeLarge 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