How can I modify negative values from two datasets based on a positive given one?

Hi. I need some help.
I wrote this code to fix two datas(First_data,Second_data) based on another one(Third_data). The datasets have the same trend, so the graph should look similar(not identic).
The code looks that it works when the values are positive but not on negative ones.
DateO={'20-Apr-2020 12:06:00','20-Apr-2020 12:07:00','20-Apr-2020 12:08:00','20-Apr-2020 12:09:00','20-Apr-2020 12:10:00','20-Apr-2020 12:11:00','20-Apr-2020 12:12:00','20-Apr-2020 12:13:00'};
DateT={'20-Apr-2020 12:06:00','20-Apr-2020 12:07:00','20-Apr-2020 12:08:00','20-Apr-2020 12:09:00','20-Apr-2020 12:10:00','20-Apr-2020 12:11:00','20-Apr-2020 12:12:00','20-Apr-2020 12:13:00'};
DateTh={'20-Apr-2020 12:06:30','20-Apr-2020 12:07:30','20-Apr-2020 12:08:30','20-Apr-2020 12:09:30','20-Apr-2020 12:10:30','20-Apr-2020 12:11:30','20-Apr-2020 12:12:30','20-Apr-2020 12:13:30'}; % Picarro
A = datetime(DateO,'InputFormat','dd-MM-yyyy HH:mm:ss');
B = datetime(DateT,'InputFormat','dd-MM-yyyy HH:mm:ss');
C = datetime(DateTh,'InputFormat','dd-MM-yyyy HH:mm:ss');
First_data=[-216,-220,-225,-232,-233,-233,-244,-246];
Second_data=[89,66,30,7,9.6,-5.8,-12,-16];
Third_data=[7.59,3.52,3.8,3.21,2,3.42,2.3,4.36];
figure;
left={Third_data,Third_data};
right={First_data,Second_data};
right_time = {A, B};
xlab=["Third data"," Third data"];
ylab=["First data","Second data"];
for i=1:length(left)
x = left{i};
y = right{i};
t = right_time{i};
if i == 1
Coeff(i) = max(y)/max(x);
else
Coeff(i) = max(x)/max(y);
end
y(y>0) = y(y>0).*Coeff(i);
y(y<0) = y(y<0).*Coeff(i);
Clb_values{i} = y;
Clb = Clb_values{i};
subplot(2,1,1*i);
yyaxis left;
plot(C, x);
ylabel('Third_data')
yyaxis right;
plot(t,Clb);
ylabel(ylab(i))
end
Clb_1=Clb_values{1,1};
Clb_2=Clb_values{1,2};
Thank you

5 Comments

Could you explain more about what is the modification you are trying to do given those data
First_data=[-216,-220,-225,-232,-233,-233,-244,-246];
Second_data=[89,66,30,7,9.6,-5.8,-12,-16];
Third_data=[7.59,3.52,3.8,3.21,2,3.42,2.3,4.36];
I am not sure but if it works with positive and not with negatives, that mean the first polt is wrong and the second is partially wrong ? case the first data contains just negatives and the second contains some negative and some positives.
I want to modify them so they give the same shape and value as the Third data. They are not totally wrong. If you plot them without any modifications you will see that they follow the Third data. Only that they need a different correction. For example, the first one needs a correction that takes into account the negative sign as well. The code I wrote works for the second data and not for the first. A separate correction I think would do that.
The coffee for the first data is negative... and when multiplying with the data you reveres the shape.
So maybe you should consider taking the abslute value of the coeff and then shifiting the graph upward.
The coffee for the first data is negative...
Even better than decaf!

Sign in to comment.

Answers (1)

maybe this works ?
if i == 1
y=y+(x-y);
Coeff(i) = abs(max(y)/max(x));
else
Coeff(i) = abs(max(x)/max(y));
end

1 Comment

I tried this and the "First data" becomes identic with the "Third data". This means that something is still wrong. Should be something to do with the coffee...

Sign in to comment.

Categories

Asked:

on 19 Nov 2020

Commented:

on 20 Nov 2020

Community Treasure Hunt

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

Start Hunting!