readline.m v4.0

version 4.0.0.0 (9.96 KB) by Carlos Adrian Vargas Aguilera
Reads the specified line(s) from a file.

4.7K Downloads

Updated 1 Jan 2016

View License

USAGE:
% 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');

NOTES:
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');

Cite As

Carlos Adrian Vargas Aguilera (2022). readline.m v4.0 (https://www.mathworks.com/matlabcentral/fileexchange/20026-readline-m-v4-0), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2014b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired by: saveascii.m v6.2 (Oct 2009)

Community Treasure Hunt

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

Start Hunting!