How can I solve a dlmread error on A2016a?

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?

 Réponse acceptée

dpb
dpb le 21 Déc 2019
Modifié(e) : dpb le 21 Déc 2019

0 votes

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 commentaires

Walter Roberson
Walter Roberson le 21 Déc 2019
dlmread will read ONLY numeric data
By the time of the R2016a release that the user is using, dlmread() is able to handle text existing in header rows or header columns.
the message is telling you there's alphanumeric data in the section of the file you're trying to read
The key there is "section of hte file you're trying to read". The 96 lines that the user requested to be skipped do not count towards being portions of the files that the user is trying to read.
% SCRIPT 1:Reading, processing and presenting CTD data
clear all;close all;clc;
name='ST1'
data=dlmread([name,'.cnv'],'',96,0);
depth=data(:,1); % depth vector
temp=data(:,2); % temperature vector
salt=data(:,3); % salinity vector
figure;
plot(temp,depth)
set(gca,'Ydir','reverse')
xlabel('Temperature (deg C)')
ylabel('Depth(m)')
bin=0.5; % thickness of the averaging bin (m)
Dbins=max(depth); % definition of the maximum depth
bins=[0.5:bin:Dbins]; % setting the bin’s vector
for i=1:length(bins)-1
ind=find(depth>=bins(i)&depth<bins(i+1));
% returns the vectors ind with the numbers of rows
% within the depth range from bins(i) to bins(i+1)
Toutput(i)=mean(temp(ind));
% calculates an average temperature Toutput(i)
% in the i-th bin
end
depthbin=[0.5+bin/2:bin:Dbins-bin/2];
hold on
plot(Toutput,depthbin,'r')
xlabel('Temperature(grad C)')
ylabel('Depth(m)')
legend('Temperature: Original data','Temperature: Smoothed data','location','southwest')
Here is the script I am trying to run with the error that has come up as seen before.
Willem Swann
Willem Swann le 27 Déc 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 le 27 Déc 2019
Modifié(e) : dpb le 27 Déc 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...

Connectez-vous pour commenter.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 21 Déc 2019

0 votes

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!

Translated by