[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question on fscanf ....

From: Nicholas Jankowski
Subject: Re: Question on fscanf ....
Date: Fri, 20 Mar 2020 15:39:17 -0400

On Fri, Mar 20, 2020 at 2:56 PM Dr.-Ing. Dieter Jurzitza
<address@hidden> wrote:
> Dear listmembers,
> I've been having a hard time with understanding the format specifiers of
> fscanf et al - still not fully done, but anyway. Let me provide an example
> what I'd like to do.
> Given you have an ASCII file with 10 columns of data and you're interested in
> the 2nd and 8th column only. The first column is a string, all other columns
> contain numbers. So I tried:
> infile=fopen(infilename, "r");
> [x]=fscanf(infile, "%*s %f %*lf %*f %*f %*f %*f %f %*f %*f", [2 inf]);
> fclose (infile)
> given that infile exists this works. However, the result is an array with 2
> columns - ok, but as I want the two columns isolated from one another for the
> sake of clarity I have to do an extra
> t=x(1,:);
> and
> y=x(2,:);
> afterwards. What I would have liked to do is a
> [t,y]= ....
> directly to assign column 2 to t and column 8 to y. Well, but what to put here
> on the right side?
> Sad enough I have to admit that it took me a matlab documentation page for an
> explanation what is required in the [2 inf] field - this does not become clear
> from the octave documentation IMHO, maybe my English capabilities are
> insufficient here ... a minimum example would be a big big help.
> The second form of fscanf() puts a "C" instead of the [2 inf] and is said to
> be more C-ish. Still I could not manage to convince octave to read the two
> values into two variables - any ideas?
> Suggestions are very much appreciated! If there is no way but splitting the
> array afterwards - ok. I had had thought that what I'd like to achieve ought
> to be possible in accordance to my understanding of the documentation, but
> how.
> Thank you very much!
> Take care

can you provide a short sample file with a few lines of data? and then
tell us what your ideal output would look like?  it might help us
advise you on how to read the file and process any input into

reply via email to

[Prev in Thread] Current Thread [Next in Thread]