hi,
i would to import data from a file like attached . I have lot file and i would like extrat some parameter in order to plot variation between eatch cast
thanks

 Accepted Answer

Walter Roberson
Walter Roberson on 14 Jul 2016
That file is not in csv format. It is also space delimited and uses two lines for each entry because the time has been folded down into the next line. There are fewer headers than there are columns because 'Sbeox0ML/LSbeox0Mm/Kg' is over two columns. You cannot use '/' to mark the end of column headings because you also have headers such as 'C1S/m'. The headers also require two lines.... Oh and I just noticed it isn't just the time that appears on the second line :(
I am working on code to import it.

3 Comments

fmt = ['%f%s%s%s', repmat('%f', 1, 19), '%s%*[^\n]\n%s', repmat('%f',1,11), '%s%*[^\n]\n'];
projectdir = 'blt-files'; %set as appropriate
dinfo = dir( fullfile(projectdir, '*.csv') );
nfiles = length(dinfo);
for K = nfiles : -1 : 1 %backwards increases efficiency
thisfile = dinfo(K).name;
filename = fullfile(projectdir, thisfile);
[~, basename, ~] = fileparts(thisfile);
filenames{K} = basename;
fid = fopen(filename, 'rt');
datacell = textscan(fid, fmt, 'HeaderLines', 10);
fclose(fid);
Bottle_Position{K} = datacell{1};
%the date/time has to be pieced together from multiple parts over 2 lines
Date_Time{K} = strcat(datacell{2},{' '}, datacell{3}, {' '}, datacell{4}, {' '}, datacell{25});
Potemp090C{K} = datacell{5};
Sal00{K} = datacell{6};
Sigma_E00{K} = datacell{7};
Potemp190C{K} = datacell{8};
Sal11{K} = datacell{9};
Sigma_E11{K} = datacell{10};
Sbeox0ML{K} = datacell{11};
LSbeox0Mm{K} = datacell{12};
PrDM_avg{K} = datacell{13};
PrDM_sdev{K} = datacell{26);
T090C_avg{K} = datacell{14};
T090C_sdev{K} = datacell{27};
T190C_avg{K} = datacell{15};
T190C_sdev{K} = datacell{28};
C0S_avg{K} = datacell{16};
C0S_sdev{K} = datacell{29};
C1S_avg{K} = datacell{17};
C1S_sdev{K} = datacell{30};
Sbeox0V_avg{K} = datacell{18};
Sbeox0V_sdev{K} = datacell{31};
FlC_avg{K} = datacell{19};
FlC_sdev{K} = datacell{32};
CStarTr0_avg{K} = datacell{20};
CStartTr0_sdev{K} = datacel{33};
Upoly0_avg{K} = datacell{21};
Upoly0_sdev{K} = datacell{34};
Upoly1_avg{K} = datacell{22};
Upoly1_sdev{K} = datacell{35};
V1_avg{K} = datacell{23};
V1_sdev{K} = datacell{36};
units_avg{K} = datacell{24}; %should be all '(avg)'
units_sdev{K} = datacell{37}; %should be all '(sdev)'
end
At the end of this, all of the *.csv files in the designated directory will be read in, and the contents placed into cell arrays, one cell entry for each file. The variables are named as closely as practical the same as the headings in the file.
In the file from PrDM to V1 there are two lines of data, one for avg and one for sdev. This has been handled in the code by creating two variables for each of the headings, one with a _avg suffix and the other with a _sdev suffix.
of course it's not a csv format ... it's .btl fil from seabird processing! and the format is really strange ....
The title of this Question asks about importing from csv files, and the file extension is .csv so everyone reading this question is going to assume that the file really is a Comma Separated Value file, but it isn't.

Sign in to comment.

More Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 13 Jul 2016
Edited: Azzi Abdelmalek on 13 Jul 2016
you can use csvread or xlsread
[ii,jj,kk]=xlsread('btl-file.csv')

Categories

Find more on App Building in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!