function varargout = SE4x4(varargin)

gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @SE4x4_OpeningFcn, ...
                   'gui_OutputFcn',  @SE4x4_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

function SE4x4_OpeningFcn(hObject, eventdata, handles, varargin)

AAAA = imread('Circuitos.jpg');
image(AAAA)
axis off

handles.output = hObject;

guidata(hObject, handles);

function varargout = SE4x4_OutputFcn(hObject, eventdata, handles) 
varargout{1} = handles.output;

function A11_Callback(hObject, eventdata, handles)

function A11_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function A21_Callback(hObject, eventdata, handles)

function A21_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function B12_Callback(hObject, eventdata, handles)

function B12_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function B22_Callback(hObject, eventdata, handles)

function B22_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function TI1_Callback(hObject, eventdata, handles)

function TI1_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function TI2_Callback(hObject, eventdata, handles)

function TI2_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function Resolver_Callback(hObject, eventdata, handles)

A = get(handles.A11,'String');
B = get(handles.B12,'String');
C = get(handles.C13,'String');
D = get(handles.D14,'String');
E = get(handles.A21,'String');
F = get(handles.B22,'String');
G = get(handles.C23,'String');
H = get(handles.D24,'String');
I = get(handles.A31,'String');
J = get(handles.B32,'String');
K = get(handles.C33,'String');
L = get(handles.D34,'String');
M = get(handles.A41,'String');
N = get(handles.B42,'String');
O = get(handles.C43,'String');
P = get(handles.D44,'String');


Q = get(handles.TI1,'String');
R = get(handles.TI2,'String');
S = get(handles.TI3,'String');
T = get(handles.TI4,'String');

if isempty(A) || isempty(B) || isempty(C) || isempty(D) || isempty(E) || isempty(F) || isempty(G) || isempty(H) || isempty(I) || isempty(J) || isempty(K) || isempty(L) || isempty(M) || isempty(N) || isempty(O) || isempty(P) || isempty(Q) || isempty(R) || isempty(S) || isempty(T)
    
        warndlg('Rellene Los Espacios Faltantes','Mensaje De Alerta');
        set(handles.RA,'String','')
        set(handles.RB,'String','')
        set(handles.RC,'String','')
        set(handles.RD,'String','')
else

        A11 = str2double(A);
        B12 = str2double(B);
        C13 = str2double(C);
        D14 = str2double(D);
        A21 = str2double(E);
        B22 = str2double(F);
        C23 = str2double(G);
        D24 = str2double(H);
        A31 = str2double(I);
        B32 = str2double(J);
        C33 = str2double(K);
        D34 = str2double(L);
        A41 = str2double(M);
        B42 = str2double(N);
        C43 = str2double(O);
        D44 = str2double(P);

        TI1 = str2double(Q);
        TI2 = str2double(R);
        TI3 = str2double(S);
        TI4 = str2double(T);

                U = [A11 B12 C13 D14;A21 B22 C23 D24;A31 B32 C33 D34;A41 B42 C43 D44];

                V = [TI1;TI2;TI3;TI4];

                INV = inv(U);

                SOL = INV*V;
                
                format rat
                FRA = rat(SOL(1,1))
                FRB = rat(SOL(2,1))
                FRC = rat(SOL(3,1))
                FRD = rat(SOL(4,1))
               

        set(handles.RA,'String',SOL(1,1))
        set(handles.RB,'String',SOL(2,1))
        set(handles.RC,'String',SOL(3,1))
        set(handles.RD,'String',SOL(4,1))
        
        set(handles.RFA,'String',FRA)
        set(handles.RFB,'String',FRB)
        set(handles.RFC,'String',FRC)
        set(handles.RFD,'String',FRD)
end

function Regresar_Callback(hObject, eventdata, handles)
close(SE4x4);
SistemasEcuaciones

function figure1_ButtonDownFcn(hObject, eventdata, handles)

function Limpiar_Callback(hObject, eventdata, handles)
A = set(handles.A11,'String','');
B = set(handles.B12,'String','');
C = set(handles.C13,'String','');
D = set(handles.D14,'String','');
E = set(handles.A21,'String','');
F = set(handles.B22,'String','');
G = set(handles.C23,'String','');
H = set(handles.D24,'String','');
I = set(handles.A31,'String','');
J = set(handles.B32,'String','');
K = set(handles.C33,'String','');
L = set(handles.D34,'String','');
M = set(handles.A41,'String','');
N = set(handles.B42,'String','');
O = set(handles.C43,'String','');
P = set(handles.D44,'String','');


Q = set(handles.TI1,'String','');
R = set(handles.TI2,'String','');
S = set(handles.TI3,'String','');
T = set(handles.TI4,'String','');

OO = set(handles.RA,'String','');
PP = set(handles.RB,'String','');
QQ = set(handles.RC,'String','');
RR = set(handles.RD,'String','');

FOO = set(handles.RFA,'String','');
FPP = set(handles.RFB,'String','');
FQQ = set(handles.RFC,'String','');
FRR = set(handles.RFD,'String','');



function A31_Callback(hObject, eventdata, handles)

function A31_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function B32_Callback(hObject, eventdata, handles)

function B32_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function TI3_Callback(hObject, eventdata, handles)

function TI3_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function C13_Callback(hObject, eventdata, handles)

function C13_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function C23_Callback(hObject, eventdata, handles)

function C23_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function C33_Callback(hObject, eventdata, handles)

function C33_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function A41_Callback(hObject, eventdata, handles)
% hObject    handle to A41 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of A41 as text
%        str2double(get(hObject,'String')) returns contents of A41 as a double


% --- Executes during object creation, after setting all properties.
function A41_CreateFcn(hObject, eventdata, handles)
% hObject    handle to A41 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function B42_Callback(hObject, eventdata, handles)
% hObject    handle to B42 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of B42 as text
%        str2double(get(hObject,'String')) returns contents of B42 as a double


% --- Executes during object creation, after setting all properties.
function B42_CreateFcn(hObject, eventdata, handles)
% hObject    handle to B42 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function C43_Callback(hObject, eventdata, handles)
% hObject    handle to C43 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of C43 as text
%        str2double(get(hObject,'String')) returns contents of C43 as a double


% --- Executes during object creation, after setting all properties.
function C43_CreateFcn(hObject, eventdata, handles)
% hObject    handle to C43 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function TI4_Callback(hObject, eventdata, handles)
% hObject    handle to TI4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of TI4 as text
%        str2double(get(hObject,'String')) returns contents of TI4 as a double


% --- Executes during object creation, after setting all properties.
function TI4_CreateFcn(hObject, eventdata, handles)
% hObject    handle to TI4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function D14_Callback(hObject, eventdata, handles)
% hObject    handle to D14 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of D14 as text
%        str2double(get(hObject,'String')) returns contents of D14 as a double


% --- Executes during object creation, after setting all properties.
function D14_CreateFcn(hObject, eventdata, handles)
% hObject    handle to D14 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function D24_Callback(hObject, eventdata, handles)
% hObject    handle to D24 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of D24 as text
%        str2double(get(hObject,'String')) returns contents of D24 as a double


% --- Executes during object creation, after setting all properties.
function D24_CreateFcn(hObject, eventdata, handles)
% hObject    handle to D24 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function D34_Callback(hObject, eventdata, handles)
% hObject    handle to D34 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of D34 as text
%        str2double(get(hObject,'String')) returns contents of D34 as a double


% --- Executes during object creation, after setting all properties.
function D34_CreateFcn(hObject, eventdata, handles)
% hObject    handle to D34 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function D44_Callback(hObject, eventdata, handles)
% hObject    handle to D44 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of D44 as text
%        str2double(get(hObject,'String')) returns contents of D44 as a double


% --- Executes during object creation, after setting all properties.
function D44_CreateFcn(hObject, eventdata, handles)
% hObject    handle to D44 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
