How can I solve a dlmread error on A2016a?

4 views (last 30 days)
I have been having an issue with producing a set of CTD data on Matlab for a few days and don't seem to understand how to solve this. I feel as though it may be an issue with importing data but I'm not 100% sure.
data=dlmread([name,'.cnv'],'',96,0);
Error using dlmread (line 147)
Mismatch between file and format character vector.
Trouble reading 'Numeric' field from file (row number 1, field number 1) ==> # </sensor>\n
Error in ctd1 (line 4)
data=dlmread([name,'.cnv'],'',96,0);
These are the error suggestions that come up, but not sure what they're suggesting as I'm quite new to Matlab and my understanding is still limited.
How can I solve the dlmread issue?
Is this issue related to importing data into Matlab?

Accepted Answer

dpb
dpb on 21 Dec 2019
Edited: dpb on 21 Dec 2019
dlmread will read ONLY numeric data; the message is telling you there's alphanumeric data in the section of the file you're trying to read. So, "Yes, Virginia, there is a problem in importing data into Matlab", but the problem is you've chosen the wrong tool for the job here.
There are many tools for the purpose in Matlab; granted, the "veritable plethora" of features is one of the things that makes initial starting difficult because it is hard to know which to choose.
Here, probably either readtable or textscan will be the choice; which, precisely we'd need to see the data file content to be able to say with certainty.
Attach a file w/ the paperclip icon so somebody here can have a look (and then tell us what you're trying to import from the file if not the whole thing as it appears).
  4 Comments
Willem Swann
Willem Swann on 27 Dec 2019
The data I am trying to import is CTD (conductivity, temperature, salinity) taken from a local tidal estuary. This is under st1 and through to st7.
dpb
dpb on 27 Dec 2019
Edited: dpb on 27 Dec 2019
Attach the file...we can only guess.
Walter had the very good thought that the line count is off by one row...
Alternatively, in lieu of receiving the data we need to solve the problem, try
opt=detectImportOptions('yourfilenamehere');
data=readtable('yourfilenamehere',opt);
and see if joy ensues. If the file structure isn't quite regular before it gets to your data, however, it'll probably require human intervention. But the humans here other than you don't have the info they require...

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 21 Dec 2019
You need to increase your 96 to (at least) 97.

Community Treasure Hunt

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

Start Hunting!