erratic results while using dlmread function

4 views (last 30 days)
HI I am using dlmread function to take specific data from .txt file. My data contains 10 text lines(rows) then set of numerical data of size 8 rows and 17 columns I want element at position 17th row(including first 10 text lines) and 14th column. So I used command like: a= dlmread('file name', '', [16 13 16 13]) But its showing error as mismatch in file format and string. When I just modified column number and entered command as a= dlmread('file name', '', [16 15 16 15] Its takes input of element from 17th row and 16th column(as expected) and does not show any error. Thus I found that when I enter columns less that 15 its showing error but for columns greater than 15 it works well. What may be the problem in this case?? Please reply soon. Urgent help is needed.

Answers (2)

Walter Roberson
Walter Roberson on 6 Sep 2011
Tips
All data in the input file must be numeric. dlmread does not read files that contain nonnumeric data, even if the specified rows and columns contain only numeric data.
Your 10 text lines of headers are creating problems. You cannot use dlmread() for that file.
(I would speculate that if you examine your text headers, you will find that the longest header has 15 columns.)
  1 Comment
Nikhil CD
Nikhil CD on 7 Sep 2011
Thanks for reply.
Just for testing, I deleted all the text data from .txt file and also made corresponding changes in row and column numbers in my program. But again its giving the same error: 'mismatch in file format and string' for specific columns(less than 13) and works well for other.
Any suggestions??

Sign in to comment.


Nikhil CD
Nikhil CD on 10 Sep 2011
The problem is not with text header.. I got the mistake..
In my file I have a column of hyphens(-), which is causing error in dlmread. I just deleted that column 'manually'( keeping all the text in the file as it is) and run the prgram again. It worked well without any error.
So now what I need to do is to remove the column of hypen from .txt file. Can I write matlab program to do this? I have to read 250 files and some of them are having even two coulmns of hyphen. Is there any function using which I can remove all the hyphens in .txt file?
  2 Comments
Walter Roberson
Walter Roberson on 10 Sep 2011
You could, but it would possibly be easier to switch to using textscan() .
Question: are there any negative values in the file?
Nikhil CD
Nikhil CD on 12 Sep 2011
yes there are negative values as well.
I got why you asked this question. negative sign '-' will also be replaced...so in this case I have to replace '-,' (hypehn followed by comma which is delimeter) with '0,'
But how to do it..Using 'regexprep' we can replace element in a string.. I want to do similar thing but for whole file.
HOw can I do it?

Sign in to comment.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!