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

조회 수: 2 (최근 30일)
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!

채택된 답변

Renato Agurto
Renato Agurto 2015년 12월 22일
편집: Renato Agurto 2015년 12월 22일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Time Series Events에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by