-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread_vpdata.m
64 lines (57 loc) · 1.93 KB
/
read_vpdata.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
function [t W T_H T_C] = read_vpdata(path);
%----------------------------------------------------------------------
% Reads a data file from program Capstone where path is the path to data file
% (either absolute or relative). Returns a vector time containg the
% sample time, a vector energy containing the total energy used by the
% compressor at that time, and two vectors with the temperatures in the hot
% and cold reservoir at the sample times.
%
% modified version 2016-09-14 for Capstone data collection program by
% Henrik Ekerfelt
%----------------------------------------------------------------------
if nargin == 0
[FileName,PathName] = uigetfile('*');
path = fullfile(PathName,FileName);
end
en_p_pulse = 4500; % energiinkrement per puls (i joule per puls)
Mdata = fileread(path);
Mdata = strrep(Mdata,',','.');
fid = fopen('tmp.data','w');
fwrite(fid,Mdata);
fclose(fid);
values = importdata('tmp.data'); %Imports data into a struct
delete('tmp.data');
% Finds index of different values.
k = 1;
k_temp = [];
for str = values.textdata(2,:)
if cell2mat(strfind(str,'Time'))
k_time = k;
elseif cell2mat(strfind(str,'Counts'))
k_energy = k;
elseif cell2mat(strfind(str,'Temp'))
if k_temp
k_temp = [k_temp,k];
else
k_temp = k;
end
end
k = k+1;
end
time = values.data(1:end-1,k_time);
energy = [0;cumsum(values.data(2:end-1,k_energy)).*en_p_pulse];
if sum(values.data(1:end-1,k_temp(1))) > sum(values.data(1:end-1,k_temp(2)))
th = values.data(1:end-1,k_temp(1));
tc = values.data(1:end-1,k_temp(2));
else
th = values.data(1:end-1,k_temp(2));
tc = values.data(1:end-1,k_temp(1));
end
%
% byt till de gamla variabelnamnen
%
t=time;
W=energy;
T_H=th;
T_C=tc;
end