How can I modify negative values from two datasets based on a positive given one?
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Nora Khaled
2020-11-20
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!