clc;
clear all;
close all force;
workspace;
filebrowser;
format short g;
format compact;
fontSize = 14;
t = 0:300;
dailyFluct = gallery('normaldata',size(t),2);
sdata = cumsum(dailyFluct) + 20 + t/100;
figure
subplot(1, 3, 1);
plot(t, sdata, 'b-', 'LineWidth', 2);
grid on;
xlabel('Time (days)');
ylabel('data');
title('Original data', 'FontSize', fontSize);
coefficients = polyfit(t, sdata, 1);
line1 = polyval(coefficients, t);
hold on;
plot(t, line1, 'r-', 'LineWidth', 2);
legend('original y', 'Line through y');
y1min = sdata(1);
y2 = -sdata;
subplot(1, 3, 2);
plot(t, sdata, 'b-', 'LineWidth', 2);
hold on;
plot(t, line1, 'r-', 'LineWidth', 2);
plot(t, y2, 'c-', 'LineWidth', 2);
grid on;
title('Upside down data', 'FontSize', fontSize);
y2 = y2 + 2 * y1min;
plot(t, y2, 'm-', 'LineWidth', 2);
legend('original y', 'Line through y', 'Negative y', 'Negative y shifted upwards');
y3 = 2 * line1 + y2 - 2 *y1min;
subplot(1, 3, 3);
plot(t, sdata, 'b-', 'LineWidth', 2);
hold on;
plot(t, line1, 'r-', 'LineWidth', 2);
plot(t, y3, 'm-', 'LineWidth', 2);
grid on;
title('Both original and Upside down data', 'FontSize', fontSize);
legend('original y', 'Line through y', 'y3, tilted upwards');