No BSD License  

Mult&T

by

 

Find realizations of multivariable systems. Created for masters students at the University Andes.

multitool.m
function varargout = multitool(varargin)
%MULTITOOL MIMO Design Tool
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @multitool_OpeningFcn, ...
                   'gui_OutputFcn',  @multitool_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 multitool_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
FigPos=get(0,'DefaultFigurePosition');
OldUnits = get(hObject, 'Units');
set(hObject, 'Units', 'pixels');
OldPos = get(hObject,'Position');
FigWidth = OldPos(3);
FigHeight = OldPos(4);
if isempty(gcbf)
    ScreenUnits=get(0,'Units');
    set(0,'Units','pixels');
    ScreenSize=get(0,'ScreenSize');
    set(0,'Units',ScreenUnits);
    FigPos(1)=1/2*(ScreenSize(3)-FigWidth);
    FigPos(2)=2/3*(ScreenSize(4)-FigHeight);
else
    GCBFOldUnits = get(gcbf,'Units');
    set(gcbf,'Units','pixels');
    GCBFPos = get(gcbf,'Position');
    set(gcbf,'Units',GCBFOldUnits);
    FigPos(1:2) = [(GCBFPos(1) + GCBFPos(3) / 2) - FigWidth / 2, ...
                   (GCBFPos(2) + GCBFPos(4) / 2) - FigHeight / 2];
end
FigPos(3:4)=[FigWidth FigHeight];
set(hObject, 'Position', FigPos);
set(hObject, 'Units', OldUnits);
text(0,0.43,'Mult','FontName','Times','FontSize',18,'color',[0 0 0])
text(0.82,0.43,'T','FontName','Times','FontSize',18,'color',[0 0 0])
text(0.66,0.24,'k','FontName','Wingdings','FontSize',18,'color',[0 0 0])
text(0.51,0.43,'k','FontName','Wingdings','FontSize',18,'color',[1 0 0])
text(0.36,0.61,'k','FontName','Wingdings','FontSize',18,'color',[0 0 0])

fin2=[handles.canonf handles.nmreal handles.mreal handles.balr handles.mor  handles.schar];
fin=[handles.bst handles.bsa handles.bsb handles.bsc handles.bsd ...
    handles.bdp handles.bdq handles.detp handles.redlmpf handles.tryagain];
fin1=[handles.sstomtf handles.sstolmpf handles.sstormpf handles.mtftolmpf...
    handles.mtftormpf handles.mtftolcf handles.mtftorcf handles.mpftomtf...
    handles.mpftoss handles.iscolred handles.isrowred handles.iscon...
    handles.isobsv handles.stepss1 handles.stepmt handles.coxmode handles.fcomp];

set(fin1,'visible','off')
set(fin,'enable','inactive')
v=ver('MATLAB');
v=str2double(v.Version);
if v<=7
    set(fin2,'enable','off')
    set(handles.text39,'visible','off')
else
    set(fin2,'enable','inactive')    
end
ot=timerfind('tag','myt');
if isempty(ot)
    t1=timer('ExecutionMode','fixedrate','period',240,'StartDelay',10,'Tag','myt');
    t1.TimerFcn={'mytimer',1};
    t1.StopFcn={'mytimer',9};
    start(t1)
end


function varargout = multitool_OutputFcn(hObject, eventdata, handles) 
varargout{1} = handles.output;
    if isequal(floor(now),734138)
        h=errordlg('Your Evaluation Mult&T for this product has expired','!!--Error--!!');
        waitfor(h)
        figure1_CloseRequestFcn(hObject, eventdata, handles)        
    end


function g11_Callback(hObject, eventdata, handles)
ftstring(1,1,handles)
function g12_Callback(hObject, eventdata, handles)
ftstring(1,2,handles)
function g13_Callback(hObject, eventdata, handles)
ftstring(1,3,handles)
function g14_Callback(hObject, eventdata, handles)
ftstring(1,4,handles)
function g21_Callback(hObject, eventdata, handles)
ftstring(2,1,handles)
function g22_Callback(hObject, eventdata, handles)
ftstring(2,2,handles)
function g23_Callback(hObject, eventdata, handles)
ftstring(2,3,handles)
function g24_Callback(hObject, eventdata, handles)
ftstring(2,4,handles)
function g31_Callback(hObject, eventdata, handles)
ftstring(3,1,handles)
function g32_Callback(hObject, eventdata, handles)
ftstring(3,2,handles)
function g33_Callback(hObject, eventdata, handles)
ftstring(3,3,handles)
function g34_Callback(hObject, eventdata, handles)
ftstring(3,4,handles)
function g41_Callback(hObject, eventdata, handles)
ftstring(4,1,handles)
function g42_Callback(hObject, eventdata, handles)
ftstring(4,2,handles)
function g43_Callback(hObject, eventdata, handles)
ftstring(4,3,handles)
function g44_Callback(hObject, eventdata, handles)
ftstring(4,4,handles)
% --------------------------------------------------------------------
function ftstring(i,j,handles)
G=get(handles.mtf,'userdata');
[num den]=tfdata(G(i,j));
num=cell2mat(num);
den=cell2mat(den);
i=1;
if length(num)~=1
    while num(i)==0
        num(i)=[];
    end
end
if length(num)~=1
    num=char(factor(poly2sym(num,'s')));    
end
den=factor(poly2sym(den,'s'));
set(handles.text3,'string',num)
set(handles.text4,'string',char(den))
% --------------------------------------------------------------------
function bdp_Callback(hObject, eventdata, handles)
P=get(handles.bdp,'userdata');
set(handles.editpq,'userdata',P)
h=handles.editpq;
mpfstring(P,h)
% --------------------------------------------------------------------
function bdq_Callback(hObject, eventdata, handles)
Q=get(handles.bdq,'userdata');
set(handles.editpq,'userdata',Q)
h=handles.editpq;
mpfstring(Q,h)
% --------------------------------------------------------------------
function mpfstring(M,h)
cl=class(M);
if strcmp(cl,'cell')
    [M]=cell2sym(M);
end
[fm cm]=size(M);
c='';
for i=1:fm,
    c1{i}='';
    for j=1:cm,
        c{i,j}='[';
        c{i,j}=strcat(c{i,j},char(M(i,j)));
        c{i,j}=strcat(c{i,j},']');
        c{i,j}=strcat(c{i,j},',  ');
    end
    c1{i}=strcat(c1{i},c{i,:});        
end
c = cellstr(c1);
set(h,'String',c)
% --------------------------------------------------------------------
function rd2_Callback(hObject, eventdata, handles)
set(handles.mpf,'userdata',0)
function rd1_Callback(hObject, eventdata, handles)
set(handles.mpf,'userdata',1)
% --------------------------------------------------------------------
function bsa_Callback(hObject, eventdata, handles)
x.data=get(hObject,'userdata');
if ~isreal(x.data)
    x.data=noreal(x.data);
end
x.rowheader= {'A'};
x.clab='x';x.rlab='x';
x.top= 390;
x.left =25;
datagrid(x,handles.uipanel11)
% --------------------------------------------------------------------
function bsb_Callback(hObject, eventdata, handles)
x.data=get(hObject,'userdata');
if ~isreal(x.data)
    x.data=noreal(x.data);
end
x.rowheader= {'B'};
x.clab='u';x.rlab='x';
x.top= 390;
x.left =25;
datagrid(x,handles.uipanel11)
% --------------------------------------------------------------------
function bsc_Callback(hObject, eventdata, handles)
x.data=get(hObject,'userdata');
if ~isreal(x.data)
    x.data=noreal(x.data);
end
x.rowheader= {'C'};
x.clab='x';x.rlab='y';
x.top= 390;
x.left =25;
datagrid(x,handles.uipanel11)
% -------------------------------------------------------------------- 
function bsd_Callback(hObject, eventdata, handles)
x.data=get(hObject,'userdata');
x.rowheader= {'D'};
x.clab='u';x.rlab='y';
x.top= 390;
x.left =25;
datagrid(x,handles.uipanel11)
% --------------------------------------------------------------------
function canonf_Callback(hObject, eventdata, handles)
val=get(hObject,'value');
a=get(handles.bsa,'userdata');
b=get(handles.bsb,'userdata');
c=get(handles.bsc,'userdata');
if val~=17    
    [v Q A B C]=canonform(a,b,c,val);
elseif val==17
    [v Q A B C]=canonform(a,b,c,'jordan');
end
if ~isequal(A,0)
    set(handles.bsa,'userdata',A);
    set(handles.bsb,'userdata',B);
    set(handles.bsc,'userdata',C);
    set(handles.bst,'userdata',Q,'enable','on','TooltipString','Matrix Transformation');
end
hObject=handles.bsa;
bsa_Callback(hObject,eventdata,handles)

     
     
  
% --------------------------------------------------------------------
function tryagain_Callback(hObject, eventdata, handles)
a=exist('system.mat','file');
if a==2
    s=load('system.mat');
    name=fieldnames(s);
    if ismember({'op','n'},name)
        try
            h = waitbar(0,'Mult&T Design GUI is Loading. Please wait...'); 
            if  s.op==1
                A=s.A;B=s.B;C=s.C;D=s.D;
                G=ss2mtf(A,B,C,D);
                sys=ss(A,B,C,D);
                try
                    [P Q]=ss2lmpf(sys);
                    [P Q]=sym2cell(P,Q);  
                catch
                    [P Q]=mtf2lmpf(G);          
                end
                 waitbar(1/4)                            
            elseif s.op==2
                G=s.sys;
                [A B C D]=dssdata(G);
                 waitbar(1/4)
                [P Q]=mtf2lmpf(G);                
            elseif s.op==3
                P=s.P;Q=s.Q;
                [A B C D]=lmpf2ss(P,Q);
                waitbar(1/4)
                G=lcf2mtf(P,Q);                 
            end
             waitbar(3/4)
             close(h)
            ponerm(handles,P,Q,0,A,B,C,D,G,s.op)            
        catch
            %close(h)
            errordlg('System not Found','!! Error !!')            
        end        
    end   
end

% --------------------------------------------------------------------
function nmreal_Callback(hObject, eventdata, handles)
val=get(hObject,'value');
G=get(handles.mtf,'userdata');
switch val
    case 1
        [A B C D]=gilbertform(G);
        set(handles.bst,'enable','off');
    case 2
        [A B C D T]=hoform(G,0);
        set(handles.bst,'userdata',T,'enable','on');
    case 3
        [A B C D T]=hoform(G,1);
        set(handles.bst,'userdata',T,'enable','on');
    case 4
        [A B C D]=jordanform(G);
        set(handles.bst,'enable','off');     
    case 5
        [A B C D]=exjordanform(G);
        set(handles.bst,'enable','off');        
    case 6
        [A B C D]=wolovichform(G);
        set(handles.bst,'enable','off');
    case 7
        [A B C D]=ssdata(G);
        set(handles.bst,'enable','off');
    case 8 
       [sys T]=canon(G,'modal');
        A=sys.a;B=sys.b;C=sys.c;D=sys.d;
        if ~isempty(T)
            set(handles.bst,'userdata',T,'enable','on');
        end
 end
set(handles.bsa,'userdata',A)
set(handles.bsb,'userdata',B)
set(handles.bsc,'userdata',C)
set(handles.bsd,'userdata',D)
hObject=handles.bsa;
bsa_Callback(hObject,eventdata,handles)
% --------------------------------------------------------------------
function mreal_Callback(hObject, eventdata, handles)
val=get(hObject,'value');
G=get(handles.mtf,'userdata');
switch val
    case 1
        [A B C D]=minhoform(G);
    case 2
        [A B C D]=minjordanform(G);
    case 3
        [A B C D]=silvermanform(G);
    case 4
        P=get(handles.bdp,'userdata');
        Q=get(handles.bdq,'userdata');
        P=normcell(P,'c');
        [A B C D]=gauthierform(P,Q);
    case 5
        [A B C D]=lcfform(G);
    case 6
        [A B C D]=rcfform(G);
    case 7
        A=get(handles.bsa,'userdata');
        B=get(handles.bsb,'userdata');
        C=get(handles.bsc,'userdata');
        D=get(handles.bsd,'userdata');
        sys=ss(A,B,C,D);
        sysm=minreal(sys);
        A=sysm.a;B=sysm.b;C=sysm.c;    
end
set(handles.bst,'enable','off');
set(handles.bsa,'userdata',A)
set(handles.bsb,'userdata',B)
set(handles.bsc,'userdata',C)
set(handles.bsd,'userdata',D)
hObject=handles.bsa;
bsa_Callback(hObject,eventdata,handles)


function mor_Callback(hObject, eventdata, handles)
%va lo de reduccion de modelos
v=ver('Robust');
v=v.Version;
if strcmp(v,'2.0.10') || isempty(v)
    warndlg('Version Toolbox Robust Control is precated')
    set(hObject,'enable','off')
else
    val=get(hObject,'value');
    h=inputdlg('Write the order of reduction','Order Model Reduction',1);
    h=str2double(h);
    G=get(handles.mtf,'userdata');
    if ~isempty(h)
        switch val
            case 1
                [sys info] = balancmr(G,h);
            case 2
                [sys info] = schurmr(G,h);
            case 3
                [sys info] = hankelmr(G,h);
        end
        set(handles.bst,'enable','off');
        set(handles.bsa,'userdata',sys.a)
        set(handles.bsb,'userdata',sys.b)
        set(handles.bsc,'userdata',sys.c)
        set(handles.bsd,'userdata',sys.d)
        set(handles.text33,'string',info.ErrorBound)
        hObject=handles.bsa;
        bsa_Callback(hObject,eventdata,handles)
    end
end

function balr_Callback(hObject, eventdata, handles)
val=get(hObject,'value');
switch val
    case 1
        A=get(handles.bsa,'userdata');
        B=get(handles.bsb,'userdata');
        C=get(handles.bsc,'userdata');
        D=get(handles.bsd,'userdata');
        sys=ss(A,B,C,D);
        [sysb,T] = ssbal(sys);   
        set(handles.bsa,'userdata',sysb.a)
        set(handles.bsb,'userdata',sysb.b)
        set(handles.bsc,'userdata',sysb.c)
        set(handles.bsd,'userdata',sysb.d)
        set(handles.bst,'userdata',T,'enable','on')
        hObject=handles.bsa;
        bsa_Callback(hObject,eventdata,handles)
    case 2
        G=get(handles.mtf,'userdata');
         [sysb,T] = balreal(G);
        set(handles.bsa,'userdata',sysb.a)
        set(handles.bsb,'userdata',sysb.b)
        set(handles.bsc,'userdata',sysb.c)
        set(handles.bsd,'userdata',sysb.d)
        set(handles.bst,'userdata',T,'enable','on')
        hObject=handles.bsa;
        bsa_Callback(hObject,eventdata,handles)
    case 3 
        A=get(handles.bsa,'userdata');
        B=get(handles.bsb,'userdata');
        C=get(handles.bsc,'userdata');
        D=get(handles.bsd,'userdata');
        sysb=ss(A,B,C,D);
        Wc=gram(sysb,'c');
        x.data=Wc;
        x.rowheader= {'G'};
        x.clab='x';x.rlab='x';
        x.top= 400;
        x.left =20;
        datagrid(x,handles.uipanel11)       
    case 4
        A=get(handles.bsa,'userdata');
        B=get(handles.bsb,'userdata');
        C=get(handles.bsc,'userdata');
        D=get(handles.bsd,'userdata');
        sysb=ss(A,B,C,D);
        Wo=gram(sysb,'o');
        x.data=Wo;
        x.rowheader= {'G'};
        x.clab='x';x.rlab='x';
        x.top= 400;
        x.left =20;
        datagrid(x,handles.uipanel11)       
end

% --------------------------------------------------------------------
function sstomtf_Callback(hObject, eventdata, handles)
 A=get(handles.bsa,'userdata');
 B=get(handles.bsb,'userdata');
 C=get(handles.bsc,'userdata');
 D=get(handles.bsd,'userdata');
 G=ss2mtf(A,B,C,D);
 set(handles.mtf,'userdata',G)

% --------------------------------------------------------------------
function sstolmpf_Callback(hObject, eventdata, handles)
A=get(handles.bsa,'userdata');
B=get(handles.bsb,'userdata');
C=get(handles.bsc,'userdata');
D=get(handles.bsd,'userdata');
sys=ss(A,B,C,D);
[P Q]=ss2lmpf(sys);
if ~isempty(P)
    [P Q]=sym2cell(P,Q);
    set(handles.bdp,'userdata',P)
    set(handles.bdq,'userdata',Q)
    set(handles.rd2,'value',1)
    set(handles.mpf,'userdata',0)
    h=handles.editpq;
    mpfstring(P,h)
end




% --------------------------------------------------------------------
function sstormpf_Callback(hObject, eventdata, handles)
A=get(handles.bsa,'userdata');
B=get(handles.bsb,'userdata');
C=get(handles.bsc,'userdata');
D=get(handles.bsd,'userdata');
sys=ss(A,B,C,D);
[P Q]=ss2rmpf(sys);
if ~isempty(P)
    [P Q]=sym2cell(P,Q);
    set(handles.bdp,'userdata',P)
    set(handles.bdq,'userdata',Q)
    set(handles.rd1,'value',1)
    set(handles.mpf,'userdata',1)
end


% --------------------------------------------------------------------
function mtftolmpf_Callback(hObject, eventdata, handles)
G=get(handles.mtf,'userdata');
[P Q]=mtf2lmpf(G);
set(handles.bdp,'userdata',P)
set(handles.bdq,'userdata',Q)
set(handles.rd2,'value',1)
set(handles.rd1,'value',0)
set(handles.mpf,'userdata',0)
set(handles.redlmpf,'userdata',0)
h=handles.editpq;
mpfstring(P,h)

% --------------------------------------------------------------------
function mtftormpf_Callback(hObject, eventdata, handles)
G=get(handles.mtf,'userdata');
[P Q]=mtf2rmpf(G);
set(handles.bdp,'userdata',P)
set(handles.bdq,'userdata',Q)
set(handles.rd1,'value',1)
set(handles.rd2,'value',0)
set(handles.mpf,'userdata',1)
set(handles.redlmpf,'userdata',0)
h=handles.editpq;
mpfstring(P,h)

% --------------------------------------------------------------------
function mtftolcf_Callback(hObject, eventdata, handles)
G=get(handles.mtf,'userdata');
[P Q]=mtf2lcf(G);
[P Q]=sym2cell(P,Q);
set(handles.bdp,'userdata',P)
set(handles.bdq,'userdata',Q)
set(handles.rd2,'value',1)
set(handles.rd1,'value',0)
set(handles.mpf,'userdata',0)
set(handles.redlmpf,'userdata',1)
h=handles.editpq;
mpfstring(P,h)

% --------------------------------------------------------------------
function mtftorcf_Callback(hObject, eventdata, handles)
G=get(handles.mtf,'userdata');
[P Q]=mtf2rcf(G);
[P Q]=sym2cell(P,Q);
set(handles.bdp,'userdata',P)
set(handles.bdq,'userdata',Q)
set(handles.rd1,'value',1)
set(handles.rd2,'value',0)
set(handles.mpf,'userdata',1)
set(handles.redlmpf,'userdata',1)
h=handles.editpq;
mpfstring(P,h)


% --------------------------------------------------------------------
function mpftomtf_Callback(hObject, eventdata, handles)
P=get(handles.bdp,'userdata');
Q=get(handles.bdq,'userdata');
lr=get(handles.mpf,'userdata');
if lr==0
    G=lcf2mtf(P,Q);
elseif lr==1
    G=rcf2mtf(P,Q);
end
set(handles.mtf,'userdata',G);


% --------------------------------------------------------------------
function mpftoss_Callback(hObject, eventdata, handles)
P=get(handles.bdp,'userdata');
Q=get(handles.bdq,'userdata');
lr=get(handles.mpf,'userdata');
op=get(handles.redlmpf,'userdata');
if lr==0
    if op==0
        [A B C D]=lmpf2ss(P,Q);
    elseif op==1
        G=lcf2mtf(P,Q);
        [A B C D]=lcfform(G);
    end
elseif lr==1
    if op==0
        [A B C D]=rmpf2ss(P,Q);
    elseif op==1
        G=rcf2mtf(P,Q);
        [A B C D]=rcfform(G);
    end
end
set(handles.bsa,'userdata',A);
set(handles.bsb,'userdata',B);
set(handles.bsc,'userdata',C);
set(handles.bsd,'userdata',D);
hObject=handles.bsa;
bsa_Callback(hObject,eventdata,handles)

% --------------------------------------------------------------------
function schar_Callback(hObject, eventdata, handles)
var=get(hObject,'value');
set(handles.bst,'enable','off')
G=get(handles.mtf,'userdata');
switch var
    case 1
        [a b c d]=ssdata(G);
        sys=ss(a,b,c,d);
        sysm=minreal(sys);
        clc
        p=eig(sysm.a);
        p=round(p*100000)/100000;
        set(handles.editpq,'string',num2str(p))
       
    case 2
        try
            [m p z]=smform(G);
            p=double(z);
            set(handles.editpq,'string',num2str(p))
        catch
             [p z]=pzmap(G);
             set(handles.editpq,'string',z)             
        end       
    case 3 
        try
            rg=rga(G);
            set(handles.editpq,'string',num2str(rg))
        catch
             warndlg('Matrix entries must be univariate polynomials in p and square')
        end     
      
    case 4
        try
            [g]=smform(G);
            h=handles.editpq;
            mpfstring(g,h)            
        catch
            warndlg('Matrix entries must be univariate polynomials in p and square')
        end     
end
% --------------------------------------------------------------------

function bst_Callback(hObject, eventdata, handles)
x.data=get(hObject,'userdata');
x.rowheader= {'T'};
x.clab='x';x.rlab='x';
x.top= 390;
x.left =25;
datagrid(x,handles.uipanel11)

function detp_Callback(hObject, eventdata, handles)
P=get(handles.bdp,'userdata');
P=cell2sym(P);
dep=det(P);
dep=expand(dep);
set(handles.editpq,'userdata',dep)
h=handles.editpq;
mpfstring(dep,h)

function redlmpf_Callback(hObject, eventdata, handles)
val=get(handles.rd2,'value');
if val==1
    P=get(handles.bdp,'userdata');
    Q=get(handles.bdq,'userdata');
    [P Q]=mpfred(P,Q);
    h=handles.editpq;
    mpfstring(P,h)
    [P Q]=sym2cell(P,Q);
    set(handles.bdp,'userdata',P)
    set(handles.bdq,'userdata',Q)
end

%--------------------------------------------------------------------
function impom_Callback(hObject, eventdata, handles)
h=sys_import;
waitfor(h)
tryagain_Callback(hObject, eventdata, handles)

function ponerm(handles,P,Q,lr,A,B,C,D,G,op)
set(handles.mtf,'userdata',G)
set(handles.bdp,'userdata',P)
set(handles.bdq,'userdata',Q)
set(handles.mpf,'userdata',lr)
set(handles.bsa,'userdata',A)
set(handles.bsb,'userdata',B)
set(handles.bsc,'userdata',C)
set(handles.bsd,'userdata',D)
set(handles.tryagain,'userdata',op)
set(handles.editpq,'userdata',P)
set(handles.redlmpf,'userdata',0);
fe=[handles.g11 handles.g12 handles.g13 handles.g14 handles.g21 handles.g22...
    handles.g23 handles.g24 handles.g31 handles.g32 handles.g33 handles.g34...
    handles.g41 handles.g42 handles.g43 handles.g44];
set(fe,'enable','off')
[fg cg]=size(G);
k=1;
for i=1:cg,
    for j=1:fg,
        h=findobj('tag',sprintf('g%d%d',j,i));
        set(h,'enable','on')      
        k=k+1;
    end
end
fin=[handles.bsa handles.bsb handles.bsc handles.bsd ...
    handles.canonf handles.nmreal handles.mreal handles.balr handles.mor...
    handles.schar handles.bdp handles.bdq handles.detp handles.redlmpf...
    handles.tryagain];
fin1=[handles.sstomtf handles.sstolmpf handles.sstormpf handles.mtftolmpf...
    handles.mtftormpf handles.mtftolcf handles.mtftorcf handles.mpftomtf...
    handles.mpftoss handles.iscolred handles.isrowred handles.iscon...
   handles.isobsv handles.stepss1 handles.stepmt handles.coxmode handles.fcomp];
set(fin,'enable','on')
set(fin1,'visible','on')
h=handles.editpq;
mpfstring(P,h)
if lr==0
    set(handles.rd2,'value',1)
    set(handles.rd1,'value',0)
elseif lr==1
    set(handles.rd2,'value',0)
    set(handles.rd1,'value',1)
end
x.top= 390;
x.left =25;
x.rowheader= {'A'};
x.clab='x';
x.rlab='x';
if ~isreal(A)
    A=noreal(A);
end
x.data=A;
datagrid(x,handles.uipanel11)
v=mindeg(G);
set(handles.text31,'string',v)

% --------------------------------------------------------------------
function expom_Callback(hObject, eventdata, handles)
button = questdlg('What model want to export?','Export','SS','MPF','MTF','SS');
if isequal(button,'SS')
    A=get(handles.bsa,'userdata');
    B=get(handles.bsb,'userdata');
    C=get(handles.bsc,'userdata');
    D=get(handles.bsd,'userdata');
    save export A B C D
    h = msgbox('Your model is export.mat','Export','none');
    waitfor(h)
elseif isequal(button,'MTF')
        G=get(handles.mtf,'userdata');
        save export G
        h = msgbox('Your model is export.mat','Export','none');
        waitfor(h)
elseif isequal(button,'MPF')
        P=get(handles.bdp,'userdata');
        Q=get(handles.bdq,'userdata');
        lr=get(handles.mpf,'userdata');
        save export P Q lr
        h = msgbox('Your model is export.mat','Export','none');
        waitfor(h)
end   

% --------------------------------------------------------------------
function savem_Callback(hObject, eventdata, handles)
[file,path] = uiputfile('*.mat','Save Models As');
if ~isequal(file,0)
    P=get(handles.bdp,'userdata');
    Q=get(handles.bdq,'userdata');
    A=get(handles.bsa,'userdata');
    B=get(handles.bsb,'userdata');
    C=get(handles.bsc,'userdata');
    D=get(handles.bsd,'userdata');
    lr=get(handles.mpf,'userdata');
    G=get(handles.mtf,'userdata');
    save(file,'P','Q','lr','A','B','C','D','G')
end


% --------------------------------------------------------------------
function loadm_Callback(hObject, eventdata, handles)
 [filename, pathname] = uigetfile( ...
        {'*.mat','Mat - Files(*.mat)';},...
        'Select System');
try
    s=[pathname filename];
    load(s,'P','Q','lr','A','B','C','D','G')
    ponerm(handles,P,Q,lr,A,B,C,D,G,1)
catch
    errordlg('Load System Error','!! Error !!')
end


% --------------------------------------------------------------------
function printm_Callback(hObject, eventdata, handles)
printdlg(handles.figure1)

% --------------------------------------------------------------------
function printfig_Callback(hObject, eventdata, handles)
print(gcbf)

% --------------------------------------------------------------------
function stepss1_Callback(hObject, eventdata, handles)
A=get(handles.bsa,'userdata');
if isreal(A)
    B=get(handles.bsb,'userdata');
    C=get(handles.bsc,'userdata');
    D=get(handles.bsd,'userdata');
    figure,step(A,B,C,D)
else
    errordlg('Model is Complex, use conversin to Real','!!--Error--!!')
end
        

% --------------------------------------------------------------------
function stepmt_Callback(hObject, eventdata, handles)
G=get(handles.mtf,'userdata');
figure,step(G)


% --------------------------------------------------------------------
function mathelp_Callback(hObject, eventdata, handles)
web http://www.mathtools.net

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


% --------------------------------------------------------------------
function iscolred_Callback(hObject, eventdata, handles)
P=get(handles.bdp,'userdata');
i=iscolred(P);
if i==1
    set(handles.editpq,'string','P is of column reduced')
elseif i==0
    set(handles.editpq,'string','P not is of column reduced')
end

% --------------------------------------------------------------------
function isrowred_Callback(hObject, eventdata, handles)
P=get(handles.bdp,'userdata');
i=isrowred(P);
if i==1
    set(handles.editpq,'string','P is of row reduced')
elseif i==0
    set(handles.editpq,'string','P not is of row reduced')
end

% --------------------------------------------------------------------
function iscon_Callback(hObject, eventdata, handles)
P=get(handles.bdp,'userdata');
Q=get(handles.bdq,'userdata');
lr=get(handles.mpf,'userdata');
if lr==1
    set(handles.editpq,'string','Rigth MPF always controlable')
elseif lr==0
    [i pnc]=islmpfc(P,Q);
    if i==1
        set(handles.editpq,'string','Left MPF is controlable')
    elseif i==0
        set(handles.editpq,'string',sprintf('Left MPF not is controlable of pole %d',pnc))
    end
end

% --------------------------------------------------------------------
function isobsv_Callback(hObject, eventdata, handles)
lr=get(handles.mpf,'userdata');
if lr==0
    set(handles.editpq,'string','Rigth MPF always observable')
end

function coxmode_Callback(hObject, eventdata, handles)
bu=questdlg('Are you sure, the Space-state is in Jordan form?','Ctrb and Obsv for Mode');
if isequal(bu,'Yes')
    A=get(handles.bsa,'userdata');
    B=get(handles.bsb,'userdata');
    C=get(handles.bsc,'userdata');
    k=coXm(A,B,C);
    x.data=k;
    x.rowheader= {'k'};
    x.rlab='p';
    x.collabels={'pole';'ctrb';'obsv'};
    x.top= 390;
    x.left =25;
    datagrid(x,handles.uipanel11)
end

function M=noreal(M)
[fm cm]=size(M);
a=M;
M=[];
for i=1:fm
    for j=1:cm
        M{i,j}=num2str(a(i,j));
    end
end
return

% --------------------------------------------------------------------
function comtoreal_Callback(hObject, eventdata, handles)
A=get(handles.bsa,'userdata');
B=get(handles.bsb,'userdata');
C=get(handles.bsc,'userdata');
if ~isreal(A)
    [A B C]=cx2rJ(A,B,C);
    set(handles.bsa,'userdata',A)
    set(handles.bsb,'userdata',B)
    set(handles.bsc,'userdata',C)   
    hObject=handles.bsa;
    bsa_Callback(hObject,eventdata,handles)
end
% --------------------------------------------------------------------
function examplesmht_Callback(hObject, eventdata, handles)
button = questdlg('What models do you want to see?','Examples','SS','MPF','MTF','SS');
if isequal(button,'SS')
   web ss.mht -browser
elseif isequal(button,'MTF')
    web mtf.mht -browser
elseif isequal(button,'MPF')
    web mpf.mht -browser
end   
%-------------------------------------------------------------------------
function cancel_Callback(hObject, eventdata, handles)
ot=timerfind('tag','myt');
if ~isempty(ot)
    ot.StopFcn='';
    stop(ot)
   delete(ot)
end
close(gcbf)


function figure1_CloseRequestFcn(hObject, eventdata, handles)
delete(hObject);
ot=timerfind('tag','myt');
if ~isempty(ot)
   ot.StopFcn='';
   stop(ot)
   delete(ot)
end

% --------------------------------------------------------------------
function fcomp_Callback(hObject, eventdata, handles)
m=get(handles.editpq,'userdata');
digits(3)
if isequal(class(m),'cell')
    m=cell2sym(m);
end
h=handles.editpq;
mpfstring(vpa(m),h)

% --------------------------------------------------------------------
function sstow_Callback(hObject, eventdata, handles)
A=get(handles.bsa,'userdata');
B=get(handles.bsb,'userdata');
C=get(handles.bsc,'userdata');
D=get(handles.bsd,'userdata');
assignin('base','A',A);
assignin('base','B',B);
assignin('base','C',C);
assignin('base','D',D);

% --------------------------------------------------------------------
function mtftow_Callback(hObject, eventdata, handles)
G=get(handles.mtf,'userdata');
assignin('base','Gt',G);

% --------------------------------------------------------------------
function mpftow_Callback(hObject, eventdata, handles)
P=get(handles.bdp,'userdata');
Q=get(handles.bdq,'userdata');
[P Q]=cell2sym(P,Q);
assignin('base','P',P);
assignin('base','Q',Q);


% --------------------------------------------------------------------
function isconss_Callback(hObject, eventdata, handles)
A=get(handles.bsa,'userdata');
B=get(handles.bsb,'userdata');
co=ctrb(A,B);
if isequal(rank(A),rank(co))
    set(handles.editpq,'string','State Space is controlable')
else
     set(handles.editpq,'string','State Space not is controlable')
end


% --------------------------------------------------------------------
function isobsvss_Callback(hObject, eventdata, handles)
A=get(handles.bsa,'userdata');
C=get(handles.bsc,'userdata');
co=obsv(A,C);
if isequal(rank(A),rank(co))
    set(handles.editpq,'string','State Space is observable')
else
     set(handles.editpq,'string','State Space not is observable')
end





Contact us