How to read a txt and store in a variable using the linefeed/carriage return

3 ビュー (過去 30 日間)
Hanna Dulay
Hanna Dulay 2019 年 12 月 2 日
回答済み: Image Analyst 2019 年 12 月 2 日
function readstring = read_form(textfile)
readstring = []; %empty readstring
text=fopen(textfile);
if text~=-1
while ~ feof(text)
txt= fgets(text)
h=sprintf('txt \r')
end
fclose(textfile);
end
end
This is what I did so far, but it's not working

回答 (1 件)

Image Analyst
Image Analyst 2019 年 12 月 2 日
If you want to read a text file line-by-line, do this:
% Open the file for reading in text mode.
fileID = fopen(fullFileName, 'rt');
% Read the first line of the file.
textLine = fgetl(fileID);
while ischar(textLine)
% Print out what line we're operating on.
fprintf('%s\n', textLine);
% Read the next line.
textLine = fgetl(fileID);
end
% All done reading all lines, so close the file.
fclose(fileID);

カテゴリ

Help Center および File ExchangeLow-Level File I/O についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by