Clear Filters
Clear Filters

how can i linearise a data from a excel file (time vs temperature) and then extend the line from plotted data in graph and to find area under the curve

3 views (last 30 days)
clc
clear All
calibration=xlsread('Calibration.xlsx','Tabelle1','A1:B21600');
[~, ~, raw0_0] = xlsread( 'Calibration.xlsx','Tabelle1','A1:A21600'); %%%
[~, ~, raw0_1] = xlsread( 'Calibration.xlsx','Tabelle1','B1:B21600'); %%%
raw = [raw0_0,raw0_1];
raw(cellfun(@(x) ~isempty(x) && isnumeric(x) && isnan(x),raw)) = {''};
R = cellfun(@(x) ~isnumeric(x) && ~islogical(x),raw); % Find non-numeric cells
raw(R) = {NaN}; % Replace non-numeric cells
data = reshape([raw{:}],size(raw));
Time = data(:,1);
Temp = data(:,2);
clearvars data raw raw0_0 raw0_1 R cellVectors;
idx = find(Temp==0);
while any(idx)
Temp(idx) = Temp(idx-2);
idx = find(Temp==0);
end
beforeperiod=xlsread('Calibration.xlsx','Tabelle1','A1:B11372');
mainperiod=xlsread('Calibration.xlsx','Tabelle1','A11373:B11751');
afterperiod=xlsread('Calibration.xlsx','Tabelle1','A11752:B21600');
START1 =mainperiod(1,1); ENDE1 = mainperiod(62,1); %%calibration
START2 = afterperiod(1,1); ENDE2 = afterperiod(end,end); %%Measurement
Q=1224;
c_begin = Temp(START1);
time_c_begin = START1;
c_end = Temp(ENDE1);
time_c_end = ENDE1;
time_main_begin = START2;
f=inline(' sum( ( (N(1).*d+N(2))-Tempo() ).^2 ) ', 'N', 'd', 'Tempo'); %funktion f(x) = m*x+t Linear Equation
format long %no exp output display parameter
options = optimset('MaxFunEvals' , 3000, 'MaxIter', 3000);
bla=round(time_c_begin-1000);
x=1000:1:bla; % all X For fitting prior period_C
param_beforeperiode=fminsearch(f, [0,0]',options,x, Temp(x)');
%bla1=round(time_c_end*1.01);
bla2=round(time_main_begin-1000);
x=(time_c_end+1200):1:bla2; % all X For fitting afterperiode_C
param_afterperiode=fminsearch(f, [0,0]',options,x, Temp(x)');
g=@(x) param_beforeperiode(1)*x + param_beforeperiode(2); %% below straight line
h=@(x) param_afterperiode(1)*x + param_afterperiode(2); %% above straight line
%Determination Function T
ende = time_c_end-400;
start = time_c_begin;
m = (Temp(ende) - Temp(start))/(ende - start);
t = Temp(start) / (m * start);
%t = c_begin / (m * time_c_begin);
%%Determination of times from area compensation
T=@(x) m*x + t; %straight line equation Heating
A=1;
B=10;
deltaAlt1=100000;
iMax=time_c_end+500; %maximum values current index
jMin=time_c_begin-750; %minimum values current index
iresult=0;
jresult=0;
i=time_c_end;
j=time_c_begin;
while (i<iMax) %Nested loop to determine the maximum i and minimum j for the smallest area
while (j>jMin)
A = integral(T, start, j) - integral(g, start, j);
B = integral(h, i, ende) - integral(T, i, ende);
surf1=abs(abs(A)-abs(B));
if(surf1<deltaAlt1)
deltaAlt1=surf1;
iresult=i;
jresult=j;
end
j=j-1;
end
i=i+1;
j=time_c_begin;
iMax;
end
iresult; %obere Grenze
jresult; %untere Grenze
Tbefor=g(iresult);
Tafter=h(jresult);
deltaTemp=Tafter-Tbefore;
C=Q/deltaTemp;
plot(Time,Temp);
so here first figure which i got from my experiment and 2nd one is my referance plot. now how can i filter the errors and make the data linearise and then extend a line like red colour dotted line(in 2nd fig) from that i want to draw another line perpendicularly which has to cut the graph with equal areas(A') and i want to find out the exact point where it is intersecting the measurement plotted data.
I'm using R2019b
finally i want to made a output like 2nd figure. Try to help me out
Thankyou All

Answers (1)

Raunak Gupta
Raunak Gupta on 19 Mar 2020
Hi,
You may look here for removing sudden spike from plot. It uses median filter for removing noise. You can use interp1 for interpolating data and plotting the red dotted line. For drawing the perpendicular lines, I would suggest filling the area instead of plotting lines. Plotting lines can be very tedious in terms of writing code whereas you may use patch which essentially create a shaded area. For finding the intersection point you can take average of two corner points of inflection where plot changes its direction. I think the graph is symmetric across those two points.
Hope it helps.

Products

Community Treasure Hunt

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

Start Hunting!