% program pro vykresleni grafu BP Malouskova

clear all
close all


X =	[1.41	1.41	1.42	1.42	1.43	1.47	1.47	1.48	1.48	1.48];
Y = [2.30	2.31	2.32	2.32	2.32	2.33	2.33	2.34	2.34	2.35    ...
    2.37	2.37	2.37	2.37	2.38	2.38	2.42	2.42	2.43	2.43	...
    2.43	2.43	2.43	2.44	2.44	2.44	2.48	2.52	2.53	2.53	...
    2.53	2.54];


Z = [	57	59	60	58	58	69	70	68.5	74	70.5;
    	48	49	45	49	49	59	60	57.5	63.5	60;
    	50	50	51	51	50	61	61	58	64	61;
    	48	49	50	49	49	59	60	58	63	60;
    	50	51	52	51	50	62	62	60	66	62;
    	45	46	46	46	45	56	56.5	55	60	56.5;
    	49	49	48.5	48	48	59.5	60	58	63	60;
    	47	47	48	48	47.5	57	58	57	61	57.5;
    	48	48	48	48	48	58	59	57.5	62.5	59;
    	46	48	45	48	47	58.5	59	58	62.5	59;
    	48	47	48	47	47	58	58	57	61	59;
    	46	46	45.5	46	45	56	57	55	60	57;
    	48	49	48	49	48	57	57.5	56	60	57.5;
    	50	50	50	50	50	60	61	59.5	64.5	61.5;
    	45	46	46	46	45	55	56	55	59	56;
    	41	41	41	41	41	51	52	48.5	53	53;
    	41	41	42	42	40	48.5	49	47	52	49;
    	48.5	50	49	49	50	59	59	59	63	60;
    	41	41.5	41	41	41	50	50.5	49	54	51;
        41	40	40.5	41.5	41	50	51	49	54	51;
    	40	40	40	40	40	49	50	49	53	50;
    	41.5	42	42	41	41	51	51	50	55	52;
    	40	40	40	40	40	49	49	48.5	52.5	49;
    	41.5	41	41	41	41.5	50	51	49.5	54	51;
    	41	41	41	41	41	50	50.5	49	54	51;
    	39	39	39	39	39	45	46	45	49	45.5;
    	38	38	38.5	38	37.5	45	46.5	45	49	45;
    	23	28	23	28.5	29	34	35	34	35.5	35;
        30.5	30	31	30	30	36	36	36	37	37;
    	33	32	33	32.5	32.5	39	39.5	38	41	41;
    	29	29	29.5	29	29	35	35	34	36	36;
    	28.5	28.5	28.5	28.5	28.5	34	34	34	35	35];
    
% zpracovani dat - prumerovani, aby vznikl relevantni graf
% X
poz = 1;
vecX(poz) = 1;
for ii = 2:length(X)
    if X(vecX(poz)) ~= X(ii)
        poz = poz + 1;
        vecX(poz) = ii;
    end
end

Xmod = X(vecX);
Zm1 = zeros([length(Y) length(Xmod)]);
for ii = 1:(length(vecX)-1)
    Zm1(:,ii) = mean(Z(:,vecX(ii):(vecX(ii+1)-1)),2);
end
Zm1(:,length(vecX)) = mean(Z(:,vecX(length(vecX)):length(X)),2);

% Y
poz = 1;
vecY(poz) = 1;
for ii = 2:length(Y)
    if Y(vecY(poz)) ~= Y(ii)
        poz = poz + 1;
        vecY(poz) = ii;
    end
end

Ymod = Y(vecY);
Zmod = zeros([length(Ymod) length(Xmod)]);
for ii = 1:(length(vecY)-1)
    Zmod(ii,:) = mean(Zm1(vecY(ii):(vecY(ii+1)-1),:),1);
end
Zmod(length(vecY),:) = mean(Zm1(vecY(length(vecY)):length(Y),:),1);


% grafy
figure
contourf(Xmod,Ymod,Zmod)
colorbar
xlabel('Prumer vstupni trysky [mm]')
ylabel('Prumer vystupni trysky [mm]')
grid on


figure
surf(Xmod,Ymod,Zmod)
xlabel('Prumer vstupni trysky [mm]')
ylabel('Prumer vystupni trysky [mm]')
zlabel('Tlakovy spad [kPa]')