clear; xdel(winsid()); clc; PLOT_STEP = 10; LAB_FS = 3; d = fscanfMat('posilek.txt'); t = d(1:PLOT_STEP:$, 1)/1000; y = d(1:PLOT_STEP:$, 2); u = d(1:PLOT_STEP:$, 4); p = d(1:PLOT_STEP:$, 6); iStep = find(diff(p) > 0); iStart1 = 1; tBefore = t(iStep(1)); if tBefore > 5 then iStart1 = find(t >= tBefore - 5, 1); tBefore = 5; end iStart2 = find(t > t(iStep(2)) - tBefore, 1); len = min(iStep(2) - iStart1, length(t) - iStart2) - 1; iEnd1 = iStart1 + len; iEnd2 = iStart2 + len; tr = t(iStart1:iEnd1); tr = tr - t(iStep(1)); yr1 = y(iStart1:iEnd1); yr2 = y(iStart2:iEnd2); ur1 = u(iStart1:iEnd1); ur2 = u(iStart2:iEnd2); subplot(2, 1, 1); plot(tr, [yr1 yr2]); h = legend('z regulatorem PID', 'bez regulatora'); h.font_size=3; title('Odpowiedź na zakłócenie (posiłek)', 'fontsize', 3); xlabel('t [s] - skala 1:300', 'fontsize', LAB_FS); ylabel('glukoza [mg/dL]', 'fontsize', LAB_FS); xgrid; subplot(2, 1, 2); plot(tr, [ur1 ur2]); h = legend('z regulatorem PID', 'bez regulatora'); h.font_size=3; xlabel('t [s] - skala 1:300', 'fontsize', LAB_FS); ylabel('insulina [%]', 'fontsize', LAB_FS); xgrid;