help-octave
[Top][All Lists]
Advanced

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

Re: Read file containing multiple data types


From: Thomas D. Dean
Subject: Re: Read file containing multiple data types
Date: Fri, 2 Nov 2018 22:31:27 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1

On 11/3/18 3:08 AM, Saji Kuttan wrote:
Hi,

I have a text file which is attached. The file has some header lines,
that have to be skipped. I am trying to read the data in the file with
different choices such as load, importdata, and fscanf. I think only
fscanf can be used here. Even with fscanf, I have some problems.

I used fscanf as :
*
*
*for i=1:33
[d,c1,c2,t]=fscanf(fid," %d %s %s %f", "C");
printf("%d %f\n", d,t)
x=fgetl(fid);  % to skip remaining part of the line
end
*
*
*
**
This code is not perfect because:

(1) I have to manually count the number of lines in the text file. I
don't know to apply automatic EOF.
(2) There are some missing data, given as "..." at the end. Here the
numeric field is changed to character. How it can be solved?

So please tell me how to read this file and save the data into different
variables.


Since you have a mixture of data, it may be better to use fgetl and
process each line.

Write a script to read the file and print each line using the while
statement.  Then, add conditions to handle each of the types of lines.

The labeled lines at the top of the file can be detected and processed
with the if statement.

The lines containing only 59.5E and 60 look like stray entries.  But,
they can also be handled with the if statement.

The data lines are the else or fall through position.  You can use the
sscanf function and process them based on the number of elements scanned
and any error returned.

Tom Dean


reply via email to

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