[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: textread substitution
From: |
Philip Nienhuis |
Subject: |
Re: textread substitution |
Date: |
Tue, 18 Dec 2012 12:33:14 -0800 (PST) |
ash wrote
> Hi all,
>
> I need to substitute textread function because i hade to use an old
> version of Octave.
Exactly what version?
> Every guide I read tell the same thing: use fscanf.
> But fscanf works differently.
> I have a file.txt made in this way
>
> acb
> qwertyuiop
> mickey
> mouse
> ...
>
> I need to get a vector in wich every cell is an entire row of this file
> (and not a matrix with a single letter for every cell).
> Can you help me ?
>
> Thanks a lor
Use something like <very rough):
<pre-allocate cell array, otherwise your code will take forever>
:
fid = fopen (...)
str = '';
while (ischar (str))
str = fgetl (fid, ....)
<append str to cell array>
endwhile
See: help fgetl
----or (even uglier)----
<open file>
str = fgets (file, <very_big_number_sufficient_to_read_entire_file>)
vector = strsplit (str, "\n")
See: help fgets
As fgets and fgetl are very similar they might be interchanged here.
(I don't know strsplit's performance but is has been tuned up by one of the
devs a while ago so shouldn't be too bad).
Philip
--
View this message in context:
http://octave.1599824.n4.nabble.com/textread-substitution-tp4648054p4648058.html
Sent from the Octave - General mailing list archive at Nabble.com.