View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
readline.m v4.0

3.9 | 8 ratings Rate this file 1 Download (last 30 days) File Size: 9.96 KB File ID: #20026 Version: 4.0
image thumbnail

readline.m v4.0



22 May 2008 (Updated )

Reads the specified line(s) from a file.

| Watch this File

File Information

% Reads the first line (default)
s = readline('data.txt');
% Reads the 8th line
s = readline('data.txt',8);
% Reads the [1 2 4 8] lines
s = readline('data.txt',[1 2 4 8]);
% Reads last 7 lines
s = readline('data.txt',[-7; -1]);
% Or just, reads the whole file
s = readline('data.txt','all');

In general, the output is a cell of strings. You may force a string matrix output with a third argument
s = readline('data.txt','all','string');


Saveascii.M V6.2 (Oct 2009) inspired this file.

MATLAB release MATLAB 8.4 (R2014b)
MATLAB Search Path
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (12)
01 Sep 2011 Simon Musall

Simon Musall (view profile)

Very handy, thanks for the submission

11 Nov 2009 Martin Richard

Well done

22 Apr 2009 Carlos Adrian Vargas Aguilera

Is not true Gabriel, it need to be like that so to be able to generate range from negative inputs. The author.

Comment only
02 Apr 2009 Gabriel Akira Schreiber

Thank you.

When called readline(file, lines) and lines is a vector, it should not matter wether lines is a row or column vector.

15 Jul 2008 Peter K. Lord

Very practical and easy to use.

10 Jun 2008 Carlos Adrian Vargas Aguilera

New version ready.

Comment only
02 Jun 2008 Carlos Adrian Vargas Aguilera

Us is terrible right... the code can be improved to be much more faster and it even has some errors (do not close the file, etc). Please wait to new submition...

28 May 2008 Urs (us) Schwarz

sorry, but for once(!) i strongly and distinctly disagree with mr shvorob and jd: this is NOT the way to do it in a typical 21st century computational environment.

28 May 2008 John D'Errico

Sorry, I forgot to add the rating.

28 May 2008 John D'Errico

Yes, I agree with Dimitri. This is not a world class piece of code, in the sense that it solves some problem of Nobel prize importance. This is only a wrapper for some simple calls.

But as Dimitri said, it does what it claims to do. It is well documented. It has an H1 line, proper error messages. I find it a pleasure to see code well done. Maybe I'm just relieved to find something well done in comparison to the rest of the crop uploaded to the file exchange on this day. Regardless, I'll give this a 5 rating. If you need/want something that does what this does, then this code does it well.

Comment only
27 May 2008 Carlos Adrian Vargas Aguilera

Just for fun, Dimitri (and more clearer writing of course)...

Comment only
27 May 2008 Dimitri Shvorob

So much code for a fairly straightforward FGETL wrapper? Still, it works, no complaints.

08 Jun 2009 1.1

V3.0 Rewritten code. Negative NLINES values now indicated number of line from the End-of-File, instead of from the last line. New pairwise optional inputs for TEXTSCAN.

01 Jan 2016 4.0

V4.0 Now accepts 'all' input. Uses TEXTSCAN instead of TEXTREAD.

Contact us