function varargout = GUI_2_all(varargin)
% GUI_2_all MATLAB code for GUI_2_all.fig
%      GUI_2_all, by itself, creates a new GUI_2_all or raises the existing
%      singleton*.
%
%      H = GUI_2_all returns the handle to a new GUI_2_all or the handle to
%      the existing singleton*.
%
%      GUI_2_all('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in GUI_2_all.M with the given input arguments.
%
%      GUI_2_all('Property','Value',...) creates a new GUI_2_all or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before GUI_2_all_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to GUI_2_all_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help GUI_2_all

% Last Modified by GUIDE v2.5 03-May-2019 23:50:37

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @GUI_2_all_OpeningFcn, ...
                   'gui_OutputFcn',  @GUI_2_all_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before GUI_2_all is made visible.
function GUI_2_all_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to GUI_2_all (see VARARGIN)

% Choose default command line output for GUI_2_all
handles.output = hObject;

%%
set(handles.Gui2,'Units','normalized','Position',[0 0 1 1],'Name','Zobrazení záznamu');

global indexy;global norma;global p_data;
h=findobj('Tag','Gui1');
indexy = getappdata(h,'index');

norma = getappdata(h,'norma');
norma=struct2cell(norma);
norma=norma{1,1};

p_data= getappdata(h,'pacient');
p_data=struct2cell(p_data);
p_data=p_data{1,1};
%% title
tituly={'Hip Flexion/Extension';'Hip Ab/Adduction';'Hip Rotation';'Knee Flexion/Extension';'Knee Ab/Adduction';'Knee Rotation';'Ankle Dorsi/Plantar';'Ankle Ab/Adduction';'Foot Progress Angles';'Pelvic Tilt';'Pelvic Obliquity';'Pelvic Rotation'};
%%
axes(handles.all);
cla(handles.all,'reset');
vel=[1 4 7 10 2 5 8 11 3 6 9 12];

for m=1:length(vel);
    subplot(3,4,m);
    variable_n1=norma{vel(m),1};  
    prumer_n1=variable_n1(1,:);
    std_n1=variable_n1(2,:);
    x=1:size(variable_n1,2);
    patch([x fliplr(x)],[prumer_n1-(2*std_n1) fliplr(prumer_n1+(2*std_n1))],[0.9 0.9 0.9]);hold on;
    y1=p_data{vel(m),1};y2=p_data{vel(m),2};
    plot(y1,'b','LineWidth',1.5);plot(y2,'r','LineWidth',1.5);
    axis tight; box on;
    xlabel('% krokového cyklu','FontSize',8.2);ylabel('Úhel [°]','FontSize',8.2);
    title(tituly{vel(m),1},'FontWeight','bold','FontSize',10);
    handles.(['axes',num2str(m)])=subplot(3,4,m);
    axh=gca;
    set(axh,'YGrid','on');set(axh,'Layer','top');
end

lgd = legend({'\bfNorma',['\bfLevá' char(10) 'noha'],['\bfPravá' char(10) 'noha']},'Position',[0.039 0.4 0.02 0.25],'Orientation','vertical','Color','#F0F0F0','FontSize',10); 
handles.legenda=lgd;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes GUI_2_all wait for user response (see UIRESUME)
% uiwait(handles.Gui2);

% --- Outputs from this function are returned to the command line.
function varargout = GUI_2_all_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in close.
function close_Callback(hObject, eventdata, handles)
% hObject    handle to close (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
close(gcf);  

% --- Executes on button press in save.
function save_Callback(hObject, eventdata, handles)
% hObject    handle to save (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

axes1fig=figure();
set(axes1fig,'Visible','off');set(axes1fig,'Units','Pixels','Position',get(0,'ScreenSize'));

for i=1:12
    axes(handles.(['axes',num2str(i)]));
    axes1copy=copyobj(handles.(['axes',num2str(i)]),axes1fig);
    
end
axes1copy=copyobj(handles.legenda,axes1fig);
[jmeno,cesta] = uiputfile('*.emf','Uložit jako');
if cesta == 0 
   return
end
saveas(axes1fig,jmeno);
close(axes1fig); 
msgbox('Záznam byl úspěšně uložen.');
