How can I import, extract, and average certain data from a excel/csv file?

1 vue (au cours des 30 derniers jours)
Katherine
Katherine le 22 Déc 2015
Commenté : Katherine le 22 Déc 2015
I have a large number of files that look like the csv file that is attached attached.
In this file there are distinct 'blocks' wherein the data was logged to the computer. I need to find a way to subtract each'S' value (which represents seconds of the experiment) from the previous so I can measure how long on average there was between each data point. I also need the averaged S values to be sorted into two categories: one in which 'Q' is greater than or equal to 1 and the other in which Q was = to 0.
I'm extremely new to matlab as well as coding in general and I am unsure of where to begin. If you can help me get started I would really appreciate it.
Thank you!

Réponse acceptée

Renato Agurto
Renato Agurto le 22 Déc 2015
Modifié(e) : Renato Agurto le 22 Déc 2015
This should get 2 arrays (S_vals, Q_vals) for the values of S and Q in the file and help as a start point. If you need more help in the operations you want to do, just ask
%Read file
[~,~,raw] = xlsread('Baseline Day 4 112915.csv');
%filter lines that starts with "S:" and "Q:"
S_lines = raw(strncmp('S:', raw,2));
Q_lines = raw(strncmp('Q:', raw,2));
%get values and transform to numbers
tmp = cellfun(@(x) str2double(x(3:end)), S_lines,'UniformOutput', false);
S_vals = cell2mat(tmp);
tmp = cellfun(@(x) str2double(x(3:end)), Q_lines,'UniformOutput', false);
Q_vals = cell2mat(tmp);
other commands you may find helpful:
S_Q_0 = S_vals(Q_vals == 0)) %Svalues where Q equals 0
S_Q_1 = S_vals(Q_vals >= 0)) %Svalues where Q equals 1 or greater
S_diff = S_vals - [0;S_vals(1:end-1)]; %difference to previous S values

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by