Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Text file question (another one sorry)

Subject: Text file question (another one sorry)

From: Baalzamon

Date: 27 Jan, 2010 15:39:04

Message: 1 of 2

I have a text file that i would like to import into matlab for further use.
The file is initially structured as a data table. However due to the initial compilation stage some of the entries are not valid.
The correct output would all have the same number of columns.
In this case 41 I think. Here is the problem. For some column entries the contents have merged (so not same number of columns) these i want to remove. For other lines sometimes the 'job is aborted' so only one column. This i also want to remove.


0.2 0.3 100 200 FIXED 3 4 5 10 10 2E3 3E-4
0.2 0.3 100 200 FIXED 3 4 5 10.110.1 2E3 3E-4
0.2 0.3 100 200 FIXED 3 4 5 10 NaN 2E3 3E-4

0.2 0.3 100 200 FIXED 3 4 5 10 10 2E3 3E-4

as shown above in line 2 the entry after '5' have joined, line 3 is one column and line 4 contains a NaN

Now for my request....
I thought what i could do is the following....
count the number of lines
read the first and put it into an output array.
Then move onto next, put it in a temporary array and count the number of columns. If this is less than the required discard and move onto next line, else append this to the output array.

I've tried various methods from the help files but often meet with errors due to mived formatting or difference in column sizes.

Any ideas on how to read line 1...then line 2 and so on.
Guess i'm looking for some general code along the lines of...
loop for not eof
read line and pass in array
read next line

Thanks in advance for any help.

Subject: Text file question (another one sorry)

From: Baalzamon

Date: 28 Jan, 2010 20:45:19

Message: 2 of 2

After much reading the help text I've solved this.
Used fgetl as instructed but passed each line into a dummy variable and then converted to num via str2num. Then only copied entries that had correct number of columns

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us