clear all
pkg load io

[filename,cesta]=uigetfile('*.xlsx','Vyber *.xlsx soubor:');  

[~,~,rawdata]=xlsread([cesta filename]);

%%%%%%%%%% smer X, tubus %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
smerX_tubus_data = rawdata(strcmp('x',rawdata(:,8)),:);
smerX_tubus_data = smerX_tubus_data(strcmp('tubus',smerX_tubus_data(:,9)),:);
smerX_tubus_data = smerX_tubus_data(strcmp('10',smerX_tubus_data(:,12)),:);
smerX_tubus_data = smerX_tubus_data(strcmp('1000',smerX_tubus_data(:,13)),:);
 
meta = cellfun(@isempty, smerX_tubus_data(:,14));
smerX_tubus_data = smerX_tubus_data(meta,:);
 
otacky=[24000, 18050, 12100, 6150, 200, 0];
for k=1:6
	otacky_cycle=otacky(k);
  
	meta = cellfun(@(x) isequal(x,otacky_cycle) ,smerX_tubus_data(:,6));
	meta = smerX_tubus_data(meta,:);
 
	smerX_tubus{k,1}=cell2mat(meta(:,4:5));
	smerX_tubus{k,1}=sortrows(smerX_tubus{k,1},1)
end

clear smerX_tubus_data meta


%%%%%%%%%% smer X, vretenik %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
smerX_vretenik_data = rawdata(strcmp('x',rawdata(:,8)),:);
smerX_vretenik_data = smerX_vretenik_data(strcmp('vretenik',smerX_vretenik_data(:,9)),:);
smerX_vretenik_data = smerX_vretenik_data(strcmp('10',smerX_vretenik_data(:,12)),:);
smerX_vretenik_data = smerX_vretenik_data(strcmp('1000',smerX_vretenik_data(:,13)),:);
 
%test meta = cellfun(@(x) isequal(x,1) ,smerX_vretenik_data(:,15));
%test smerX_vretenik_data = smerX_vretenik_data(meta,:);
 
meta = cellfun(@isempty, smerX_vretenik_data(:,14));
smerX_vretenik_data = smerX_vretenik_data(meta,:);

otacky=[24000, 18050, 12100, 6150, 200, 0];
for k=1:6
	otacky_cycle=otacky(k);
  
	meta = cellfun(@(x) isequal(x,otacky_cycle) ,smerX_vretenik_data(:,6));
	meta = smerX_vretenik_data(meta,:);
 
	smerX_vretenik{k,1}=cell2mat(meta(:,4:5));
	smerX_vretenik{k,1}=sortrows(smerX_vretenik{k,1},1);
end

clear smerX_vretenik_data meta


 %%%%%%%%%% smer Y, vretenik %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
smerY_data = rawdata(strcmp('y',rawdata(:,8)),:);
smerY_data = smerY_data(strcmp('vretenik',smerY_data(:,9)),:);
smerY_data = smerY_data(strcmp('10',smerY_data(:,12)),:);
smerY_data = smerY_data(strcmp('1000',smerY_data(:,13)),:);
smerY_data=smerY_data([smerY_data{:,4}]<=445,:);  %% max do dne 445, posledni mereni 2x na vreteniku
 
meta = cellfun(@isempty, smerY_data(:,14));
smerY_data = smerY_data(meta,:);
 
otacky=[24000, 18050, 12100, 6150, 200, 0];
for k=1:6
	otacky_cycle=otacky(k);
  
	meta = cellfun(@(x) isequal(x,otacky_cycle) ,smerY_data(:,6));
	meta = smerY_data(meta,:);
 
	meta_smerY{k,1}=cell2mat(meta(:,4:5));
 
	meta_smerY{k,1}=sortrows(meta_smerY{k,1},1);
 
	smerY{k,1}(:,1)=meta_smerY{k,1}(1:2:end,1);
	smerY{k,1}(:,2)=meta_smerY{k,1}(1:2:end,2);
	smerY{k,1}(:,3)=meta_smerY{k,1}(2:2:end,2);
	smerY{k,1}(:,4)=mean(smerY{k,1}(:,2:3)')';
 
	smerY_vretenik{k,1}=[smerY{k,1}(:,1),smerY{k,1}(:,4)];
	smerY_vretenik{k,1}=sortrows(smerY_vretenik{k,1},1);
end

clear smerY_data meta_smerY meta smerY


%%%% smer Y, vretenik, pouze jedno dilci mereni
smerY_data = rawdata(strcmp('y',rawdata(:,8)),:);
smerY_data = smerY_data(strcmp('vretenik',smerY_data(:,9)),:);
smerY_data = smerY_data(strcmp('10',smerY_data(:,12)),:);
smerY_data = smerY_data(strcmp('1000',smerY_data(:,13)),:);
smerY_data=smerY_data([smerY_data{:,4}]>445,:);  %% ode dne 445, potom se merilo na tubusu
  
meta = cellfun(@isempty, smerY_data(:,14));
smerY_data = smerY_data(meta,:);
 
otacky=[24000, 18050, 12100, 6150, 200, 0];
for k=1:6
	otacky_cycle=otacky(k);
  
	meta = cellfun(@(x) isequal(x,otacky_cycle) ,smerY_data(:,6));
	meta = smerY_data(meta,:);
 
	meta_smerY{k,1}=cell2mat(meta(:,4:5));
	meta_smerY{k,1}=sortrows(meta_smerY{k,1},1);

	smerY{k,1}(:,1)=meta_smerY{k,1}(1:end,1);
	smerY{k,1}(:,2)=meta_smerY{k,1}(1:end,2);
	smerY{k,1}(:,3)=meta_smerY{k,1}(1:end,2);
	smerY{k,1}(:,4)=mean(smerY{k,1}(:,2:3)')';
 
	smerY_vretenik{k,1}=[smerY_vretenik{k,1}(:,1:2);smerY{k,1}(:,1:2)];
	smerY_vretenik{k,1}=sortrows(smerY_vretenik{k,1},1)
end  

clear smerY_data meta_smerY meta smerY


%%%% smer Y, tubus
smerY_data = rawdata(strcmp('y',rawdata(:,8)),:);
smerY_data = smerY_data(strcmp('tubus',smerY_data(:,9)),:);
smerY_data = smerY_data(strcmp('10',smerY_data(:,12)),:);
smerY_data = smerY_data(strcmp('1000',smerY_data(:,13)),:);
smerY_data=smerY_data([smerY_data{:,4}]>445,:);  %% ode dne 445, potom se merilo na tubusu
 
 
meta = cellfun(@isempty, smerY_data(:,14));
smerY_data = smerY_data(meta,:);
 
otacky=[24000, 18050, 12100, 6150, 200, 0];
for k=1:6
	otacky_cycle=otacky(k);
  
	meta = cellfun(@(x) isequal(x,otacky_cycle) ,smerY_data(:,6));
	meta = smerY_data(meta,:);
 
	meta_smerY{k,1}=cell2mat(meta(:,4:5));
	meta_smerY{k,1}=sortrows(meta_smerY{k,1},1);
 
	smerY_tubus{k,1}(:,1)=meta_smerY{k,1}(1:end,1);
	smerY_tubus{k,1}(:,2)=meta_smerY{k,1}(1:end,2);
	smerY_tubus{k,1}(:,3)=meta_smerY{k,1}(1:end,2);
	smerY_tubus{k,1}(:,4)=mean(smerY_tubus{k,1}(:,2:3)')';
	smerY_tubus{k,1}=sortrows(smerY_tubus{k,1},1);
end  

clear smerY_data meta_smerY meta

 
%%%%%%%%%% smer Z, priruba %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
smerZ_data = rawdata(strcmp('z',rawdata(:,8)),:);
smerZ_data = smerZ_data(strcmp('priruba',smerZ_data(:,9)),:);
smerZ_data = smerZ_data(strcmp('10',smerZ_data(:,12)),:);
smerZ_data = smerZ_data(strcmp('1000',smerZ_data(:,13)),:);
 
meta = cellfun(@isempty, smerZ_data(:,14));
smerZ_data = smerZ_data(meta,:);
 
otacky=[24000, 18050, 12100, 6150, 200, 0];
for k=1:6
	otacky_cycle=otacky(k);
 
	meta = cellfun(@(x) isequal(x,otacky_cycle) ,smerZ_data(:,6));
	meta = smerZ_data(meta,:);
 
	meta_smerZ{k,1}=cell2mat(meta(:,4:5));

	meta_smerZ{k,1}=sortrows(meta_smerZ{k,1},1);
	
	smerZ{k,1}(:,1)=meta_smerZ{k,1}(1:2:end,1);
	smerZ{k,1}(:,2)=meta_smerZ{k,1}(1:2:end,2);
	smerZ{k,1}(:,3)=meta_smerZ{k,1}(2:2:end,2);
	smerZ{k,1}(:,4)=mean(smerZ{k,1}(:,2:3)')';
	smerZ{k,1}=sortrows(smerZ{k,1},1);
end

clear smerZ_data meta_smerZ meta



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%% LOZISKOVA %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% loziskova X, tubus
%% Predni lozisko
%%BPFO_front 2.sloupec
loziskova_meta = rawdata(strcmp('BPFO_front',rawdata(:,14)),:);
loziskova_meta = loziskova_meta(strcmp('tubus',loziskova_meta(:,9)),:);
loziskova_front_tubus(:,1:2)=cell2mat(loziskova_meta(:,4:5));
%%BPFI_front 3.sloupec
loziskova_meta = rawdata(strcmp('BPFI_front',rawdata(:,14)),:);
loziskova_meta = loziskova_meta(strcmp('tubus',loziskova_meta(:,9)),:);
loziskova_front_tubus(:,3)=cell2mat(loziskova_meta(:,5));
%%BSF_front 4.sloupec
loziskova_meta = rawdata(strcmp('BSF_front',rawdata(:,14)),:);
loziskova_meta = loziskova_meta(strcmp('tubus',loziskova_meta(:,9)),:);
loziskova_front_tubus(:,4)=cell2mat(loziskova_meta(:,5));
%%FTF_front 5.sloupec
loziskova_meta = rawdata(strcmp('FTF_front',rawdata(:,14)),:);
loziskova_meta = loziskova_meta(strcmp('tubus',loziskova_meta(:,9)),:);
loziskova_front_tubus(:,5)=cell2mat(loziskova_meta(:,5));
loziskova_front_tubus=sortrows(loziskova_front_tubus,1);


%% Zadni lozisko
%%BPFO_rear 2.sloupec
loziskova_meta = rawdata(strcmp('BPFO_rear',rawdata(:,14)),:);
loziskova_meta = loziskova_meta(strcmp('tubus',loziskova_meta(:,9)),:);
loziskova_rear_tubus(:,1:2)=cell2mat(loziskova_meta(:,4:5));
%%BPFI_rear 3.sloupec
loziskova_meta = rawdata(strcmp('BPFI_rear',rawdata(:,14)),:);
loziskova_meta = loziskova_meta(strcmp('tubus',loziskova_meta(:,9)),:);
loziskova_rear_tubus(:,3)=cell2mat(loziskova_meta(:,5));
%%BSF_rear 4.sloupec
loziskova_meta = rawdata(strcmp('BSF_rear',rawdata(:,14)),:);
loziskova_meta = loziskova_meta(strcmp('tubus',loziskova_meta(:,9)),:);
loziskova_rear_tubus(:,4)=cell2mat(loziskova_meta(:,5));
%%FTF_rear 5.sloupec
loziskova_meta = rawdata(strcmp('FTF_rear',rawdata(:,14)),:);
loziskova_meta = loziskova_meta(strcmp('tubus',loziskova_meta(:,9)),:);
loziskova_rear_tubus(:,5)=cell2mat(loziskova_meta(:,5));
loziskova_rear_tubus=sortrows(loziskova_rear_tubus,1);

%%%%%%% loziskova X, vretenik

%% Predni lozisko
%%BPFO_front 2.sloupec
loziskova_meta = rawdata(strcmp('BPFO_front',rawdata(:,14)),:);
loziskova_meta = loziskova_meta(strcmp('vretenik',loziskova_meta(:,9)),:);
loziskova_front_vretenik(:,1:2)=cell2mat(loziskova_meta(:,4:5));
%%BPFI_front 3.sloupec
loziskova_meta = rawdata(strcmp('BPFI_front',rawdata(:,14)),:);
loziskova_meta = loziskova_meta(strcmp('vretenik',loziskova_meta(:,9)),:);
loziskova_front_vretenik(:,3)=cell2mat(loziskova_meta(:,5));
%%BSF_front 4.sloupec
loziskova_meta = rawdata(strcmp('BSF_front',rawdata(:,14)),:);
loziskova_meta = loziskova_meta(strcmp('vretenik',loziskova_meta(:,9)),:);
loziskova_front_vretenik(:,4)=cell2mat(loziskova_meta(:,5));
%%FTF_front 5.sloupec
loziskova_meta = rawdata(strcmp('FTF_front',rawdata(:,14)),:);
loziskova_meta = loziskova_meta(strcmp('vretenik',loziskova_meta(:,9)),:);
loziskova_front_vretenik(:,5)=cell2mat(loziskova_meta(:,5));
loziskova_front_vretenik=sortrows(loziskova_front_vretenik,1);


%% Zadni lozisko
%%BPFO_rear 2.sloupec
loziskova_meta = rawdata(strcmp('BPFO_rear',rawdata(:,14)),:);
loziskova_meta = loziskova_meta(strcmp('vretenik',loziskova_meta(:,9)),:);
loziskova_rear_vretenik(:,1:2)=cell2mat(loziskova_meta(:,4:5));
%%BPFI_rear 3.sloupec
loziskova_meta = rawdata(strcmp('BPFI_rear',rawdata(:,14)),:);
loziskova_meta = loziskova_meta(strcmp('vretenik',loziskova_meta(:,9)),:);
loziskova_rear_vretenik(:,3)=cell2mat(loziskova_meta(:,5));
%%BSF_rear 4.sloupec
loziskova_meta = rawdata(strcmp('BSF_rear',rawdata(:,14)),:);
loziskova_meta = loziskova_meta(strcmp('vretenik',loziskova_meta(:,9)),:);
loziskova_rear_vretenik(:,4)=cell2mat(loziskova_meta(:,5));
%%FTF_rear 5.sloupec
loziskova_meta = rawdata(strcmp('FTF_rear',rawdata(:,14)),:);
loziskova_meta = loziskova_meta(strcmp('vretenik',loziskova_meta(:,9)),:);
loziskova_rear_vretenik(:,5)=cell2mat(loziskova_meta(:,5));
loziskova_rear_vretenik=sortrows(loziskova_rear_vretenik,1);



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%% OTACKOVA  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%% smer X, tubus   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

smerX_otackova_data = rawdata(strcmp('x',rawdata(:,8)),:);
smerX_otackova_data = smerX_otackova_data(strcmp('tubus',smerX_otackova_data(:,9)),:);
smerX_otackova_data = smerX_otackova_data(not(strcmp('10',smerX_otackova_data(:,12))),:);
smerX_otackova_data = smerX_otackova_data(not(strcmp('10',smerX_otackova_data(:,13))),:);
 
meta = cellfun(@isempty, smerX_otackova_data(:,14));
smerX_otackova_data = smerX_otackova_data(meta,:);
 
otacky=[24000, 18050, 12100, 6150, 200, 0];
for k=1:6
	otacky_cycle=otacky(k);
  
	meta = cellfun(@(x) isequal(x,otacky_cycle) ,smerX_otackova_data(:,6));
	meta = smerX_otackova_data(meta,:);
 
	smerX_tubus_otackova{k,1}=cell2mat(meta(:,4:5));
	smerX_tubus_otackova{k,1}=sortrows(smerX_tubus_otackova{k,1},1);
end

clear smerX_tubus_data meta smerX_otackova_data


%% smer X, vretenik  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

smerX_otackova_data = rawdata(strcmp('x',rawdata(:,8)),:);
smerX_otackova_data = smerX_otackova_data(strcmp('vretenik',smerX_otackova_data(:,9)),:);
smerX_otackova_data = smerX_otackova_data(not(strcmp('10',smerX_otackova_data(:,12))),:);
smerX_otackova_data = smerX_otackova_data(not(strcmp('10',smerX_otackova_data(:,13))),:);
 
meta = cellfun(@(x) isequal(x,1) ,smerX_otackova_data(:,15));
smerX_otackova_data = smerX_otackova_data(meta,:);
 
meta = cellfun(@isempty, smerX_otackova_data(:,14));
smerX_otackova_data = smerX_otackova_data(meta,:);
 
otacky=[24000, 18050, 12100, 6150, 200, 0];
for k=1:6
	otacky_cycle=otacky(k);
  
	meta = cellfun(@(x) isequal(x,otacky_cycle) ,smerX_otackova_data(:,6));
	meta = smerX_otackova_data(meta,:);
 
	smerX_vretenik_otackova{k,1}=cell2mat(meta(:,4:5));
	smerX_vretenik_otackova{k,1}=sortrows(smerX_vretenik_otackova{k,1},1);
end

clear smerX_vretenik_data meta smerX_otackova_data



%% smer Y, vretenik  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

smerY_data = rawdata(strcmp('y',rawdata(:,8)),:);
smerY_data = smerY_data(strcmp('vretenik',smerY_data(:,9)),:);
smerY_data = smerY_data(not(strcmp('10',smerY_data(:,12))),:);
smerY_data = smerY_data(not(strcmp('10',smerY_data(:,13))),:);
smerY_data=smerY_data([smerY_data{:,4}]<=445,:);  %% max do dne 445, potom se merilo na tubusu
 
meta = cellfun(@isempty, smerY_data(:,14));
smerY_data = smerY_data(meta,:);
 
otacky=[24000, 18050, 12100, 6150, 200, 0];
for k=1:6
	otacky_cycle=otacky(k);
  
	meta = cellfun(@(x) isequal(x,otacky_cycle) ,smerY_data(:,6));
	meta = smerY_data(meta,:);
 
	meta_smerY{k,1}=cell2mat(meta(:,4:5));
 
	meta_smerY{k,1}=sortrows(meta_smerY{k,1},1);
 
	smerY{k,1}(:,1)=meta_smerY{k,1}(1:2:end,1);
	smerY{k,1}(:,2)=meta_smerY{k,1}(1:2:end,2);
	smerY{k,1}(:,3)=meta_smerY{k,1}(2:2:end,2);
	smerY{k,1}(:,4)=mean(smerY{k,1}(:,2:3)')';
 
	smerY_vretenik_otackova{k,1}=[smerY{k,1}(:,1),smerY{k,1}(:,4)];
	smerY_vretenik_otackova{k,1}=sortrows(smerY_vretenik_otackova{k,1},1);
end

clear smerY_data meta_smerY meta smerY

%%% smer Y, vretenik zbytek, 1 mereni

smerY_data = rawdata(strcmp('y',rawdata(:,8)),:);
smerY_data = smerY_data(strcmp('vretenik',smerY_data(:,9)),:);
smerY_data = smerY_data(not(strcmp('10',smerY_data(:,12))),:);
smerY_data = smerY_data(not(strcmp('10',smerY_data(:,13))),:);
smerY_data=smerY_data([smerY_data{:,4}]>445,:);  %% max do dne 445, potom se merilo na tubusu
 
meta = cellfun(@isempty, smerY_data(:,14));
smerY_data = smerY_data(meta,:);
 
otacky=[24000, 18050, 12100, 6150, 200, 0];
for k=1:6
	otacky_cycle=otacky(k);
  
	meta = cellfun(@(x) isequal(x,otacky_cycle) ,smerY_data(:,6));
	meta = smerY_data(meta,:);
 
	meta_smerY{k,1}=cell2mat(meta(:,4:5));

	meta_smerY{k,1}=sortrows(meta_smerY{k,1},1);
 
	smerY{k,1}(:,1)=meta_smerY{k,1}(1:end,1);
	smerY{k,1}(:,2)=meta_smerY{k,1}(1:end,2);
	smerY{k,1}(:,3)=meta_smerY{k,1}(1:end,2);
	smerY{k,1}(:,4)=mean(smerY{k,1}(:,2:3)')';

	smerY_vretenik_otackova{k,1}=[smerY_vretenik_otackova{k,1}(:,1:2);smerY{k,1}(:,1:2)];
	smerY_vretenik_otackova{k,1}=sortrows(smerY_vretenik_otackova{k,1},1);
end

clear smerY_data meta_smerY meta smerY

%%% smer Y, tubus

smerY_data = rawdata(strcmp('y',rawdata(:,8)),:);
smerY_data = smerY_data(strcmp('vretenik',smerY_data(:,9)),:);
smerY_data = smerY_data(not(strcmp('10',smerY_data(:,12))),:);
smerY_data = smerY_data(not(strcmp('10',smerY_data(:,13))),:);
smerY_data=smerY_data([smerY_data{:,4}]>445,:);  %% max do dne 445, potom se merilo na tubusu
 
meta = cellfun(@isempty, smerY_data(:,14));
smerY_data = smerY_data(meta,:);
 
otacky=[24000, 18050, 12100, 6150, 200, 0];
for k=1:6
	otacky_cycle=otacky(k);
  
	meta = cellfun(@(x) isequal(x,otacky_cycle) ,smerY_data(:,6));
	meta = smerY_data(meta,:);
 
	meta_smerY{k,1}=cell2mat(meta(:,4:5));
	 
	meta_smerY{k,1}=sortrows(meta_smerY{k,1},1);
 
	smerY_otackova_tubus{k,1}(:,1)=meta_smerY{k,1}(1:end,1);
	smerY_otackova_tubus{k,1}(:,2)=meta_smerY{k,1}(1:end,2);
	smerY_otackova_tubus{k,1}(:,3)=meta_smerY{k,1}(1:end,2);
	smerY_otackova_tubus{k,1}(:,4)=mean(smerY_otackova_tubus{k,1}(:,2:3)')';
	smerY_otackova_tubus{k,1}=sortrows(smerY_otackova_tubus{k,1},1);
end

clear smerY_data meta_smerY meta


%%%%%%%%%% smer Z, priruba %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
smerZ_data = rawdata(strcmp('z',rawdata(:,8)),:);
smerZ_data = smerZ_data(strcmp('priruba',smerZ_data(:,9)),:);
smerZ_data = smerZ_data(not(strcmp('10',smerZ_data(:,12))),:);
smerZ_data = smerZ_data(not(strcmp('10',smerZ_data(:,13))),:);
 
meta = cellfun(@isempty, smerZ_data(:,14));
smerZ_data = smerZ_data(meta,:);
 
otacky=[24000, 18050, 12100, 6150, 200, 0];
for k=1:6
	otacky_cycle=otacky(k);
 
	meta = cellfun(@(x) isequal(x,otacky_cycle) ,smerZ_data(:,6));
	meta = smerZ_data(meta,:);
 
	meta_smerZ{k,1}=cell2mat(meta(:,4:5));
 
	meta_smerZ{k,1}=sortrows(meta_smerZ{k,1},1);
 
	smerZ_otackova{k,1}(:,1)=meta_smerZ{k,1}(1:2:end,1);
	smerZ_otackova{k,1}(:,2)=meta_smerZ{k,1}(1:2:end,2);
	smerZ_otackova{k,1}(:,3)=meta_smerZ{k,1}(2:2:end,2);
	smerZ_otackova{k,1}(:,4)=mean(smerZ_otackova{k,1}(:,2:3)')';
	smerZ_otackova{k,1}=sortrows(smerZ_otackova{k,1},1);
end

clear smerZ_data meta_smerZ meta



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%  GRAFY %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

tloustka=1;
velikostbodu=12;
tvarbodu='.';
tvarcary=':';

osaX='Dny mereni';
osaY='RMS rychlosti vibraci [mm/s]';

lim1=[0 4];  %% xlim mohutnosti
lim2=[0 0.6];  %% xlim loziskova
lim3=[0 4];  %% xlim
lim_dny=[0 600];

legenda_otacky=['24000 RPM';'18050 RPM'; '12100 RPM'; '6150 RPM'; '200 RPM'; '0 RPM'];
legenda_otacky_ot=['24000 RPM';'18050 RPM'; '12100 RPM'; '6150 RPM'; '200 RPM'];
legenda_lozisko=['BPFO - vnejsi krouzek';'BPFI - vnitrni krouzek';'BSF - valive telisko';'FTF - klec'];

figure('Name','Mohutnosti vibraci')

subplot(2,2,2);
%%smer X, tubus
H=plot(smerX_tubus{1,1}(:,1),smerX_tubus{1,1}(:,2),
smerX_tubus{2,1}(:,1),smerX_tubus{2,1}(:,2),
smerX_tubus{3,1}(:,1),smerX_tubus{3,1}(:,2),
smerX_tubus{4,1}(:,1),smerX_tubus{4,1}(:,2),
smerX_tubus{5,1}(:,1),smerX_tubus{5,1}(:,2),
smerX_tubus{6,1}(:,1),smerX_tubus{6,1}(:,2));
title('Mohutnost vibraci - 10-1000 Hz(mereno ve smeru X na tubusu)')
ylim(lim1)
xlim(lim_dny)
xlabel(osaX)
ylabel(osaY)
grid on
legend(legenda_otacky_ot,'Orientation','horizontal')
set(H,'LineStyle',tvarcary,'Marker',tvarbodu,'LineWidth',tloustka,'MarkerSize',velikostbodu)

subplot(2,2,1);
%%smer X, vretenik
H=plot(smerX_vretenik{1,1}(:,1),smerX_vretenik{1,1}(:,2),
smerX_vretenik{2,1}(:,1),smerX_vretenik{2,1}(:,2),
smerX_vretenik{3,1}(:,1),smerX_vretenik{3,1}(:,2),
smerX_vretenik{4,1}(:,1),smerX_vretenik{4,1}(:,2),
smerX_vretenik{5,1}(:,1),smerX_vretenik{5,1}(:,2),
smerX_vretenik{6,1}(:,1),smerX_vretenik{6,1}(:,2));
title('Mohutnost vibraci - 10-1000 Hz(mereno ve smeru X na vreteniku)')
ylim(lim1)
xlim(lim_dny)
xlabel(osaX)
ylabel(osaY)
grid on
legend(legenda_otacky)
set(H,'LineStyle',tvarcary,'Marker',tvarbodu,'LineWidth',tloustka,'MarkerSize',velikostbodu)

subplot(2,2,3);
%%smer Y, vretenik
H=plot(smerY_vretenik{1,1}(:,1),smerY_vretenik{1,1}(:,2),
smerY_vretenik{2,1}(:,1),smerY_vretenik{2,1}(:,2),
smerY_vretenik{3,1}(:,1),smerY_vretenik{3,1}(:,2),
smerY_vretenik{4,1}(:,1),smerY_vretenik{4,1}(:,2),
smerY_vretenik{5,1}(:,1),smerY_vretenik{5,1}(:,2),
smerY_vretenik{6,1}(:,1),smerY_vretenik{6,1}(:,2));
title('Mohutnost vibraci - 10-1000 Hz(mereno ve smeru Y na vreteniku)')
ylim(lim1)
xlim(lim_dny)
xlabel(osaX)
ylabel(osaY)
grid on
legend(legenda_otacky)
set(H,'LineStyle',tvarcary,'Marker',tvarbodu,'LineWidth',tloustka,'MarkerSize',velikostbodu)

subplot(2,2,4);
%%smer Z, priruba
H=plot(smerZ{1,1}(:,1),smerZ{1,1}(:,4),
smerZ{2,1}(:,1),smerZ{2,1}(:,4),
smerZ{3,1}(:,1),smerZ{3,1}(:,4),
smerZ{4,1}(:,1),smerZ{4,1}(:,4),
smerZ{5,1}(:,1),smerZ{5,1}(:,4),
smerZ{6,1}(:,1),smerZ{6,1}(:,4)) ;
title('Mohutnost vibraci - 10-1000 Hz(mereno ve smeru Z na prirube)')
ylim(lim1)
xlim(lim_dny)
xlabel(osaX)
ylabel(osaY)
grid on
legend(legenda_otacky)
set(H,'LineStyle',tvarcary,'Marker',tvarbodu,'LineWidth',tloustka,'MarkerSize',velikostbodu)

%%%%%%% Loziskova %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

figure('Name','Chybove frekvence lozisek')
subplot(2,2,1);
%%loziskova, predni lozisko, tubus
H=plot(loziskova_front_tubus(:,1),loziskova_front_tubus(:,2),
loziskova_front_tubus(:,1),loziskova_front_tubus(:,3),
loziskova_front_tubus(:,1),loziskova_front_tubus(:,4),
loziskova_front_tubus(:,1),loziskova_front_tubus(:,5));
title('Chybove frekvence predniho loziska (mereno ve smeru X na tubusu)')
ylim(lim2)
xlim(lim_dny)
xlabel(osaX)
ylabel(osaY)
grid on
legend(legenda_lozisko)
set(H,'LineStyle',tvarcary,'Marker',tvarbodu,'LineWidth',tloustka,'MarkerSize',velikostbodu)

subplot(2,2,2);
%%loziskova, predni lozisko, vretenik
H=plot(loziskova_front_vretenik(:,1),loziskova_front_vretenik(:,2),
loziskova_front_vretenik(:,1),loziskova_front_vretenik(:,3),
loziskova_front_vretenik(:,1),loziskova_front_vretenik(:,4),
loziskova_front_vretenik(:,1),loziskova_front_vretenik(:,5));
title('Chybove frekvence predniho loziska (mereno ve smeru X na vreteniku)')
ylim(lim2)
xlim(lim_dny)
xlabel(osaX)
ylabel(osaY)
grid on
legend(legenda_lozisko)
set(H,'LineStyle',tvarcary,'Marker',tvarbodu,'LineWidth',tloustka,'MarkerSize',velikostbodu)

subplot(2,2,3);
%%loziskova, zadni lozisko, tubus
H=plot(loziskova_rear_tubus(:,1),loziskova_rear_tubus(:,2),
loziskova_rear_tubus(:,1),loziskova_rear_tubus(:,3),
loziskova_rear_tubus(:,1),loziskova_rear_tubus(:,4),
loziskova_rear_tubus(:,1),loziskova_rear_tubus(:,5));
title('Chybove frekvence zadniho loziska (mereno ve smeru X na tubusu)')
ylim(lim2)
xlim(lim_dny)
xlabel(osaX)
ylabel(osaY)
grid on
legend(legenda_lozisko)
set(H,'LineStyle',tvarcary,'Marker',tvarbodu,'LineWidth',tloustka,'MarkerSize',velikostbodu)

subplot(2,2,4);
%%smer Y, tubus
H=plot(loziskova_rear_vretenik(:,1),loziskova_rear_vretenik(:,2),
loziskova_rear_vretenik(:,1),loziskova_rear_vretenik(:,3),
loziskova_rear_vretenik(:,1),loziskova_rear_vretenik(:,4),
loziskova_rear_vretenik(:,1),loziskova_rear_vretenik(:,5));
title('Chybove frekvence zadniho loziska (mereno ve smeru X na vreteniku)')
ylim(lim2)
xlim(lim_dny)
xlabel(osaX)
ylabel(osaY)
grid on
legend(legenda_lozisko)
set(H,'LineStyle',tvarcary,'Marker',tvarbodu,'LineWidth',tloustka,'MarkerSize',velikostbodu)

%%%%%%% Otackova %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



figure('Name','RMS rychlosti vibraci na otackovych frekvencich')
subplot(2,2,2);
%%smer X, otackova, tubus
H=plot(smerX_tubus_otackova{1,1}(:,1),smerX_tubus_otackova{1,1}(:,2),
smerX_tubus_otackova{2,1}(:,1),smerX_tubus_otackova{2,1}(:,2),
smerX_tubus_otackova{3,1}(:,1),smerX_tubus_otackova{3,1}(:,2),
smerX_tubus_otackova{4,1}(:,1),smerX_tubus_otackova{4,1}(:,2),
smerX_tubus_otackova{5,1}(:,1),smerX_tubus_otackova{5,1}(:,2),
smerX_tubus_otackova{6,1}(:,1),smerX_tubus_otackova{6,1}(:,2));
title('Mohutnost vibraci - otackova frekvence (mereno ve smeru X na tubusu)')
ylim(lim3)
xlim(lim_dny)
xlabel(osaX)
ylabel(osaY)
grid on
legend(legenda_otacky_ot,'Orientation','horizontal')
set(H,'LineStyle',tvarcary,'Marker',tvarbodu,'LineWidth',tloustka,'MarkerSize',velikostbodu)

subplot(2,2,1);
%%smer X, otackova, vretenik
H=plot(smerX_vretenik_otackova{1,1}(:,1),smerX_vretenik_otackova{1,1}(:,2),
smerX_vretenik_otackova{2,1}(:,1),smerX_vretenik_otackova{2,1}(:,2),
smerX_vretenik_otackova{3,1}(:,1),smerX_vretenik_otackova{3,1}(:,2),
smerX_vretenik_otackova{4,1}(:,1),smerX_vretenik_otackova{4,1}(:,2),
smerX_vretenik_otackova{5,1}(:,1),smerX_vretenik_otackova{5,1}(:,2),
smerX_vretenik_otackova{6,1}(:,1),smerX_vretenik_otackova{6,1}(:,2));
title('Mohutnost vibraci - otackova frekvence (mereno ve smeru X na vreteniku)')
ylim(lim3)
xlim(lim_dny)
xlabel(osaX)
ylabel(osaY)
grid on
legend(legenda_otacky_ot,'Orientation','horizontal')
set(H,'LineStyle',tvarcary,'Marker',tvarbodu,'LineWidth',tloustka,'MarkerSize',velikostbodu)

subplot(2,2,3);
%%smer Y, otackova, vretenik
H=plot(smerY_vretenik_otackova{1,1}(:,1),smerY_vretenik_otackova{1,1}(:,2),
smerY_vretenik_otackova{2,1}(:,1),smerY_vretenik_otackova{2,1}(:,2),
smerY_vretenik_otackova{3,1}(:,1),smerY_vretenik_otackova{3,1}(:,2),
smerY_vretenik_otackova{4,1}(:,1),smerY_vretenik_otackova{4,1}(:,2),
smerY_vretenik_otackova{5,1}(:,1),smerY_vretenik_otackova{5,1}(:,2),
smerY_vretenik_otackova{6,1}(:,1),smerY_vretenik_otackova{6,1}(:,2));
title('Mohutnost vibraci - otackova frekvence (mereno ve smeru Y na vreteniku)')
ylim(lim3)
xlim(lim_dny)
xlabel(osaX)
ylabel(osaY)
grid on
legend(legenda_otacky_ot,'Orientation','horizontal')
set(H,'LineStyle',tvarcary,'Marker',tvarbodu,'LineWidth',tloustka,'MarkerSize',velikostbodu)

subplot(2,2,4);
%%smer Z, otackova, priruba
H=plot(smerZ_otackova{1,1}(:,1),smerZ_otackova{1,1}(:,4),
smerZ_otackova{2,1}(:,1),smerZ_otackova{2,1}(:,4),
smerZ_otackova{3,1}(:,1),smerZ_otackova{3,1}(:,4),
smerZ_otackova{4,1}(:,1),smerZ_otackova{4,1}(:,4),
smerZ_otackova{5,1}(:,1),smerZ_otackova{5,1}(:,4),
smerZ_otackova{6,1}(:,1),smerZ_otackova{6,1}(:,4)) ;
title('Mohutnost vibraci - otackova frekvence (mereno ve smeru Z na prirube)')
ylim(lim3)
xlim(lim_dny)
xlabel(osaX)
ylabel(osaY)
grid on
legend(legenda_otacky_ot,'Orientation','horizontal')
set(H,'LineStyle',tvarcary,'Marker',tvarbodu,'LineWidth',tloustka,'MarkerSize',velikostbodu)

%%% PRIDANO MERENI NA TUBUSU V Y
figure('Name','Mereni na tubus ve smeru Y')
subplot(2,2,1);
%%smer Y, mohutnost, tubus
H=plot(smerY_tubus{1,1}(:,1),smerY_tubus{1,1}(:,2),
smerY_tubus{2,1}(:,1),smerY_tubus{2,1}(:,2),
smerY_tubus{3,1}(:,1),smerY_tubus{3,1}(:,2),
smerY_tubus{4,1}(:,1),smerY_tubus{4,1}(:,2),
smerY_tubus{5,1}(:,1),smerY_tubus{5,1}(:,2),
smerY_tubus{6,1}(:,1),smerY_tubus{6,1}(:,2));
title('Mohutnost vibraci - 10-1000 Hz (mereno ve smeru Y na tubusu)')
ylim(lim1)
xlim(lim_dny)
xlabel(osaX)
ylabel(osaY)
grid on
legend(legenda_otacky_ot,'Orientation','horizontal')
set(H,'LineStyle',tvarcary,'Marker',tvarbodu,'LineWidth',tloustka,'MarkerSize',velikostbodu)

subplot(2,2,2);
%%smer Y, otackova, tubus
H=plot(smerY_otackova_tubus{1,1}(:,1),smerY_otackova_tubus{1,1}(:,2),
smerY_otackova_tubus{2,1}(:,1),smerY_otackova_tubus{2,1}(:,2),
smerY_otackova_tubus{3,1}(:,1),smerY_otackova_tubus{3,1}(:,2),
smerY_otackova_tubus{4,1}(:,1),smerY_otackova_tubus{4,1}(:,2),
smerY_otackova_tubus{5,1}(:,1),smerY_otackova_tubus{5,1}(:,2),
smerY_otackova_tubus{6,1}(:,1),smerY_otackova_tubus{6,1}(:,2));
title('Mohutnost vibraci - otackova frekvence (mereno ve smeru Y na tubusu)')
ylim(lim3)
xlim(lim_dny)
xlabel(osaX)
ylabel(osaY)
grid on
legend(legenda_otacky_ot,'Orientation','horizontal')
set(H,'LineStyle',tvarcary,'Marker',tvarbodu,'LineWidth',tloustka,'MarkerSize',velikostbodu)
