Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
Kofial
Kofial le 19 Nov 2020
Commenté : Kofial le 20 Nov 2020
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 commentaires
Matt J
Matt J le 20 Nov 2020
The coffee for the first data is negative...
Even better than decaf!

Connectez-vous pour commenter.

Réponses (1)

Nora Khaled
Nora Khaled le 20 Nov 2020
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 commentaire
Kofial
Kofial le 20 Nov 2020
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...

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by