[Top][All Lists]

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

Question on fscanf ....

From: Dr.-Ing. Dieter Jurzitza
Subject: Question on fscanf ....
Date: Fri, 20 Mar 2020 19:56:13 +0100

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


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 
Thank you very much!
Take care

Dieter Jurzitza

Dr.-Ing. Dieter Jurzitza                    76131 Karlsruhe

reply via email to

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