📄 matx_proc.m
字号:
%matx_proc is a group of functions which can be used either as an individual
%program for matrix processing or used as part of CtrlLAB.
%
% [ret1,ret2,ret3]=matx_proc(A,arg1,arg2)
%where
% A -- either a system model, matrix, or a task code
% arg1,arg2 -- extra arguments
%
%The functions available in the module are
%
% matx_controls -- creates all the control objects on main window
% matx_menu -- creates the menu system on the main window
% matx_toolbar -- creates a toolbar for Matrix Processor
% matx_init -- initializes the matrix processing interface
% disp_matrix -- displays a matrix
% matx_edit -- allows the user to edit the matrix elements
% matx_update -- updates the current matrix
% matdisp_pars -- obtains the display format
% shw_matpars -- shows the properties of the given matrix
% matx_pars -- evaluates parameters of a given matrix
% sys_disp -- displays the system state space format in the window
% matx_file -- manipulates the File menu in the program
% mat_decomp -- performs matrix decomposition
% shw_decmat -- displays a matrix in decomposition
% shw_matrix -- displays the matrix
% mat_funs -- evaluates exp(A), sin(A), cos(A)
% frame_setting -- administrates the area for matrix display
% flt_replace -- changes the float value to MATLAB string
% issquare -- detects whether a matrix given is square
% con_obsv -- detects is controllable, observable, stabilizable, and detectable.
% stab_detc -- checks the stabilizability or detectability
%
%Copyright (c) 1997-1999 by Professor Dingyu Xue
%School of Information Science and Engineering, Northeastern University
%Shenyang 110006, P R China
%Email: xue_dy@hotmail.com
%----------------------------------------------------------------------------
function ret1=matx_proc(A,arg1,arg2)
if nargin==0,
%Using this program as in independent program
A=[]; %initialize it
end
if nargin>=2
nTask=A;
switch nTask
case 0, %administrate the File menu in the program
if nargout==0, matx_file(arg1);
else, ret1=matx_file(arg1); end
case 1, disp_matrix(arg1);%display a given matrix in MATLAB or TeX format
case 2, matx_edit;%editing an existing matrix/system
case 3, matx_update;%update the matrix display
case 4, sys_disp;%redisplay the system
case 5, shw_matpars(arg1);%display the parameters of a matrix
case 6, if nargin==3, sys_disp; end %display state space model
case 7, matx_decomp(arg1); %perform matrix decompositions
case 8, shw_decmat(arg1); %display matrix decompositions
case 9, disp_matrix(arg1,[]);%prepare a matrix to display
case 10, %display a matrix
switch arg1
case 1, extra_funs(4,4,'Checked',2,3:4);
case 2, extra_funs(4,4,'Checked',3,[2,4]);
case 3, extra_funs(4,4,'Checked',4,2:3);
case 4, extra_funs(4,4,'Checked',5,[6,7]);
case 5, extra_funs(4,4,'Checked',6,[5,7]);
case 6, extra_funs(4,4,'Checked',7,[5,6]);
case 7, extra_funs(4,4,'Checked',10,11:13);
case 8, extra_funs(4,4,'Checked',11,[10,12:13]);
case 9, extra_funs(4,4,'Checked',12,[10,11,13]);
case 10, extra_funs(4,4,'Checked',13,[10:12]);
case 11, extra_funs(4,4,'Checked',[3,6,10],[2,4,5,7,11:13]);
case 12,
if get(gco,'Value')==1, extra_funs(4,4,'Checked',4,2:3);
else, extra_funs(4,4,'Checked',3,[2,4]); end
end
shw_matrix;
%if length(arg1)==0, shw_matrix;
%elseif nargin==2, shw_matrix(arg1);
%elseif nargin==3, shw_matrix(arg1, arg2); end
case {11,12,13,14}, con_obsv(nTask);
end
else
key=0; h_win=findobj('Tag','MatxProcMain');
if length(h_win)==0
%open a new window for matrix processor
h_win = figure('Units','normalized','Position',[0.12375 0.248 0.5 0.417],...
'MenuBar','none','Color',0.8*[1,1,1],'Tag','MatxProcMain','Resize','off', ...
'NumberTitle','off','Name','Matrix Processor');
%define the uicontrols on the window
[hControls,hh]=matx_controls; key=1;
else
%if it is exist, then bring it to front
figure(h_win); uu=get(h_win,'UserData'); uu{1}{1}=A;
set(h_win,'UserData',uu);
end
%program initialization, with menu, controls setting
A1=matx_init(A,h_win);
if key==1, matx_menu(A1,hControls); matx_toolbar; end
sys_disp(A1); %display current system
end
%---------------------------------------------------------------------------------
%matx_controls is used to create all the control objects on the matrix processor's
%main window.
%---------------------------------------------------------------------------------
function [hControls,hh]=matx_controls()
%define a group of filled frames to hide some unwanted parts of the matrix
hh(1)=uicontrol('Style','Frame',...%right
'Units','normalized','Position',[0.7501,0.0001,0.2498,0.9998],...
'ForegroundColor',0.8*[1,1,1],'BackgroundColor',0.8*[1,1,1]);
hh(2)=uicontrol('Style','Frame',...%bottom
'Units','normalized','Position',[0.0001,0.0001,0.9998,0.0698],...
'ForegroundColor',0.8*[1,1,1],'BackgroundColor',0.8*[1,1,1]);
hh(3)=uicontrol('Style','Frame',...%left
'Units','normalized','Position',[0.0001,0.0001,0.0499,0.9998],...
'ForegroundColor',0.8*[1,1,1],'BackgroundColor',0.8*[1,1,1]);
hh(4)=uicontrol('Style','Frame',...%top
'Units','normalized','Position',[0.0001,0.8961,0.9998,0.1038],...
'ForegroundColor',0.8*[1,1,1],'BackgroundColor',0.8*[1,1,1]);
%define the push buttons on the dialog box
hControls(1)=uicontrol('Style','PushButton','String','Real Part',...
'Units','normalized','Position',[0.80,0.87,0.17,0.08], ...
'Enable','off','CallBack','matx_proc(8,1);');
hControls(2)=uicontrol('Style','PushButton','String','Imag Part',...
'Units','normalized','Position',[0.80,0.76,0.17,0.08],...
'Enable','off','CallBack','matx_proc(8,2);');
hControls(3)=uicontrol('Style','PushButton','String','Matrix U',...
'Units','normalized','Position',[0.80,0.62,0.17,0.08],...
'Visible','off','CallBack','matx_proc(8,3);');
hControls(4)=uicontrol('Style','PushButton','String','Matrix G',...
'Units','normalized','Position',[0.80,0.51,0.17,0.08],...
'Visible','off','CallBack','matx_proc(8,4);');
hControls(5)=uicontrol('Style','PushButton','String','Matrix V',...
'Units','normalized','Position',[0.80,0.40,0.17,0.08],...
'Visible','off','CallBack','matx_proc(8,5);');
hControls(6)=uicontrol('Style','Slider',...
'Units','normalized','Position',[0.05,0.02,0.7,0.049],...
'Visible','off','CallBack','extra_funs(8,1);');
hControls(7)=uicontrol('Style','Slider',...
'Units','normalized','Position',[0.751,0.07,0.033,0.85],...
'Visible','off','CallBack','extra_funs(8,2);');
%define a set of uicontrols for matrix editting.
hControls(9)=uicontrol('Style','Edit','String','','Visible','off',...
'Units','normalized','Position',[0.30,0.88,0.20,0.08],...
'ForegroundColor',[0,0,0],'BackgroundColor',[1,1,1],...
'HorizontalAlignment','left','CallBack','matx_proc(3,1);');
%hControls(8) and (10) are no longer used.
hControls(11)=uicontrol('Style','PushButton','String','Refresh',...
'Units','normalized','Position',[0.80,0.16,0.17,0.08],...
'Visible','off','CallBack','matx_proc(6,1,1);');
hControls(12)=uicontrol('Style','PushButton','String','Exit',...
'Units','normalized','Position',[0.80,0.05,0.17,0.08],...
'CallBack','matx_proc(0,5);');
%set invisible axis
frame_setting(hControls);
%----------------------------------------------------------------------------------
%matx_menu is used to create the menu system on the matrix processor's main window.
%----------------------------------------------------------------------------------
function matx_menu(A,hControls)
%define the File menu
hMMatFile(1)=uimenu(gcf,'Label','&File');
hMMatFile(2)=uimenu(hMMatFile(1),'Label','&New Matrix...','CallBack','matx_proc(0,1);');
hMMatFile(3)=uimenu(hMMatFile(1),'Label','&Open ...','CallBack','matx_proc(0,2);');
hMMatFile(4)=uimenu(hMMatFile(1),'Label','&Save','CallBack','matx_proc(0,3);');
hMMatFile(5)=uimenu(hMMatFile(1),'Label','Save &As ...','CallBack','matx_proc(0,4);');
hMMatFile(8)=uimenu(hMMatFile(1),'Label','E&xit','Separator','on','CallBack','matx_proc(0,5);');
%define the Edit menu
hMMatEdit(1)=uimenu(gcf,'Label','&Edit');
hMMatEdit(2)=uimenu(hMMatEdit(1),'Label','&Edit an Element','CallBack','matx_proc(2,1);');
hMMatEdit(3)=uimenu(hMMatEdit(1),'Label','Show in MATLAB Format ...',...
'Separator','on','CallBack','matx_proc(1,2);');
hMMatEdit(4)=uimenu(hMMatEdit(1),'Label','Show in &TeX Format ...','CallBack','matx_proc(1,1);');
hMMatEdit(5)=uimenu(hMMatEdit(1),'Label','Show System Model','Separator','on','CallBack','matx_proc(4,[]);');
%define the matrix display Format menu
hMMat(1)=uimenu(gcf,'Label','For&mats');
hMMat(2)=uimenu(hMMat(1),'Label','&High Precision','Checked','off','CallBack','matx_proc(10,1);');
hMMat(3)=uimenu(hMMat(1),'Label','&Normal Precision','Checked','on','CallBack','matx_proc(10,2);');
hMMat(4)=uimenu(hMMat(1),'Label','&Rational Approximation','Checked','off','CallBack','matx_proc(10,3);');
hMMat(5)=uimenu(hMMat(1),'Label','&Left Justify','Checked','off','Separator','on','CallBack','matx_proc(10,4);');
hMMat(6)=uimenu(hMMat(1),'Label','&Center Justify','Checked','on','CallBack','matx_proc(10,5);');
hMMat(7)=uimenu(hMMat(1),'Label','&Right Justify','Checked','off','CallBack','matx_proc(10,6);');
hMMat(9)=uimenu(hMMat(1),'Label','&Zero Truncate','Separator','on');
hMMat(10)=uimenu(hMMat(9),'Label','No Truncate','Check','on','CallBack','matx_proc(10,7);');
hMMat(11)=uimenu(hMMat(9),'Label','10^{-14}','Check','off','CallBack','matx_proc(10,8);');
hMMat(12)=uimenu(hMMat(9),'Label','10^{-15}','Check','off','CallBack','matx_proc(10,9);');
hMMat(13)=uimenu(hMMat(9),'Label','10^{-16}','Check','off','CallBack','matx_proc(10,10);');
hMMat(8)=uimenu(hMMat(1),'Label','&Defaults','CallBack','matx_proc(10,11);');
%define the matrix Analyser menu
hMMatProp(1)=uimenu(gcf,'Label','&Analysis');
hMMatProp(2)=uimenu(hMMatProp(1),'Label','&Matrix Parameters');
hMMatProp(3)=uimenu(hMMatProp(2),'Label','&Determinant','CallBack','matx_proc(5,1);');
hMMatProp(4)=uimenu(hMMatProp(2),'Label','&Rank','CallBack','matx_proc(5,2);');
hMMatProp(5)=uimenu(hMMatProp(2),'Label','&Trace','CallBack','matx_proc(5,3);');
hMMatProp(6)=uimenu(hMMatProp(2),'Label','&Eigenvalues','CallBack','matx_proc(5,4);');
hMMatProp(7)=uimenu(hMMatProp(2),'Label','&Singular Values','CallBack','matx_proc(5,5);');
hMMatProp(8)=uimenu(hMMatProp(2),'Label','&Condition Number','CallBack','matx_proc(5,6);');
hMMatProp(9)=uimenu(hMMatProp(2),'Label','&Norm');
hMMatProp(10)=uimenu(hMMatProp(9),'Label','&1-Norm','CallBack','matx_proc(5,7);');
hMMatProp(11)=uimenu(hMMatProp(9),'Label','&2-Norm','CallBack','matx_proc(5,8);');
hMMatProp(12)=uimenu(hMMatProp(9),'Label','&Infinity-Norm','CallBack','matx_proc(5,9);');
hMMatProp(13)=uimenu(hMMatProp(9),'Label','&Frobinius-Norm','CallBack','matx_proc(5,10);');
hMMatProp(14)=uimenu(hMMatProp(9),'Label','&Norms','CallBack','matx_proc(5,12)');
hMMatProp(15)=uimenu(hMMatProp(2),'Label','&Characteristic Polynomial','CallBack','matx_proc(5,11);');
hMMatProp(16)=uimenu(hMMatProp(2),'Label','&Matrix Parameters','CallBack','matx_proc(5,13)');
hMMatProp(17)=uimenu(hMMatProp(1),'Label','&Manipulations');
hMMatProp(18)=uimenu(hMMatProp(17),'Label','&Matrix A','CallBack','matx_proc(9,1);');
hMMatProp(19)=uimenu(hMMatProp(17),'Label','&Transpose','CallBack','matx_proc(9,2);');
hMMatProp(20)=uimenu(hMMatProp(17),'Label','&Inverse','CallBack','matx_proc(9,3);');
hMMatProp(21)=uimenu(hMMatProp(17),'Label','Flip &Horizontal','CallBack','matx_proc(9,4);');
hMMatProp(22)=uimenu(hMMatProp(17),'Label','Flip &Vertical','CallBack','matx_proc(9,5);');
hMMatProp(23)=uimenu(hMMatProp(17),'Label','&Rotate 90 Degree','CallBack','matx_proc(9,6);');
hMMatProp(24)=uimenu(hMMatProp(17),'Label','&Orthonormal Basis',...
'Separator','on','CallBack','matx_proc(9,12);');
hMMatProp(25)=uimenu(hMMatProp(17),'Label','&Null Space','CallBack','matx_proc(9,13);');
hMMatProp(26)=uimenu(hMMatProp(1),'Label','&Decomposition');
hMMatProp(27)=uimenu(hMMatProp(26),'Label','&LU Decomposition','CallBack','matx_proc(7,1,1);');
hMMatProp(28)=uimenu(hMMatProp(26),'Label','&SVD Decomposition','CallBack','matx_proc(7,2,1);');
hMMatProp(29)=uimenu(hMMatProp(26),'Label','S&chur Decomposition','CallBack','matx_proc(7,3,1);');
hMMatProp(30)=uimenu(hMMatProp(26),'Label','&QR Decomposition','CallBack','matx_proc(7,4,1);');
hMMatProp(31)=uimenu(hMMatProp(26),'Label','&Hess Form','CallBack','matx_proc(7,5,1);');
hMMatProp(32)=uimenu(hMMatProp(26),'Label','&Balance Form','CallBack','matx_proc(7,6,1);');
hMMatProp(33)=uimenu(hMMatProp(1),'Label','Matrix &Evaluation');
hMMatProp(34)=uimenu(hMMatProp(33),'Label','&Exp(A)','CallBack','matx_proc(9,7);');
hMMatProp(35)=uimenu(hMMatProp(33),'Label','&Sin(A)','CallBack','matx_proc(9,8);');
hMMatProp(36)=uimenu(hMMatProp(33),'Label','&Cos(A)','CallBack','matx_proc(9,9);');
hMMatProp(37)=uimenu(hMMatProp(33),'Label','&Log(A)','CallBack','matx_proc(9,10);');
hMMatProp(38)=uimenu(hMMatProp(33),'Label','&Sqrt(A)','CallBack','matx_proc(9,11);');
if isa(A,'double')
hMSSProp=[];
else
hMSSProp(1)=uimenu(gcf,'Label','&StateSpace');
hMSSProp(2)=uimenu(hMSSProp(1),'Label','&Controllability','CallBack','matx_proc(11,[]);');
hMSSProp(3)=uimenu(hMSSProp(1),'Label','&Observability','CallBack','matx_proc(12,[]);');
hMSSProp(4)=uimenu(hMSSProp(1),'Label','&Stabilizability','CallBack','matx_proc(13,[]);');
hMSSProp(5)=uimenu(hMSSProp(1),'Label','&Detectability','CallBack','matx_proc(14,[]);');
end
%define the Help menu
hMMatHelp(1)=uimenu(gcf,'Label','&Help');
hMMatHelp(2)=uimenu(hMMatHelp(1),'Label','&Introduction to Matx_Proc','CallBack','clab_help(22);');
hMMatHelp(3)=uimenu(hMMatHelp(1),'Label','&About ...','Separator','on','CallBack','clab_help(24);');
uu={{A,A},hMMatFile,hMMatEdit,hMMat,hMMatProp,hMSSProp,hMMatHelp,hControls};
uu{10}={0,''}; set(gcf,'UserData',uu);
%-----------------------------------------------------------------------------
%matx_toolbar used to create a toolbar for Matrix Processor and it is now only
%working for mATLAB 5.2 and higher.
%-----------------------------------------------------------------------------
function matx_toolbar()
[v,d]=version; v1=eval(v(1)); v2=eval(v(3));
if v1>=5 & v2>=2,
yy=get(gcf,'Position'); screen=get(0,'ScreenSize'); ymax=yy(4)*screen(4)-20;
load ctrllab_cdata; load matx_cdata; load graf_cdata;
uicontrol('Style','PushButton','Units','pixels','Position',[5,ymax,20,20],...
'CData',fnew_dat,'CallBack','matx_proc(0,1);','TooltipString','Create New Matrix','Tag','Tools');
uicontrol('Style','PushButton','Units','pixels','Position',[25,ymax,20,20],...
'CData',fopen_dat,'CallBack','matx_proc(0,2);','TooltipString','Load Matrix','Tag','Tools');
uicontrol('Style','PushButton','Units','pixels','Position',[45,ymax,20,20],...
'CData',fsave_dat,'CallBack','matx_proc(0,3);','TooltipString','Save Matrix','Tag','Tools');
uicontrol('Style','PushButton','Units','pixels','Position',[70,ymax,20,20],...
'CData',tex_dat,'CallBack','matx_proc(1,1);','TooltipString','TeX Output','Tag','Tools');
uicontrol('Style','PushButton','Units','pixels','Position',[90,ymax,20,20],...
'CData',mat_dat,'CallBack','matx_proc(1,2);','TooltipString','MATLAB Output','Tag','Tools');
uicontrol('Style','PushButton','Units','pixels','Position',[110,ymax,20,20],...
'CData',edit_dat,'CallBack','matx_proc(2,1);','TooltipString','Edit Elements','Tag','Tools');
uicontrol('Style','PushButton','Units','pixels','Position',[135,ymax,20,20],...
'CData',left_dat,'CallBack','matx_proc(10,4);','TooltipString','Left Align','Tag','Tools');
uicontrol('Style','PushButton','Units','pixels','Position',[155,ymax,20,20],...
'CData',centre_dat,'CallBack','matx_proc(10,5);','TooltipString','Centre Align','Tag','Tools');
uicontrol('Style','PushButton','Units','pixels','Position',[175,ymax,20,20],...
'CData',right_dat,'CallBack','matx_proc(10,6);','TooltipString','Right Align','Tag','Tools');
uicontrol('Style','ToggleButton','Units','pixels','Position',[195,ymax,20,20],...
'CData',rat_dat,'CallBack','matx_proc(10,12);','TooltipString','Rational Display','Tag','Tools');
uicontrol('Style','PushButton','Units','pixels','Position',[220,ymax,20,20],...
'CData',help_dat,'CallBack','clab_help(24);','TooltipString','About Matrix Processor','Tag','Tools');
end
%-------------------------------------------------------------
%matx_init used to initialize the matrix processing interface.
%-------------------------------------------------------------
function A_new=matx_init(A,h_win)
A_new=A;
if isa(A,'double')
if length(A)==0,
h_main=findobj('Tag','CtrlLABMain');
if length(h_main)>0
%if it is part of CtrlLAB, then load system model
u0=get(h_main,'UserData'); u0=get(u0{1}(1),'UserData');
uu=get(h_win,'UserData');
A_new=ss(u0{2}); uu{1}{1}=A_new;
else
%if it is an independent program, then initialize it
A_new=[]; uu{1}{1}=A_new;
end
set(h_win,'UserData',uu);
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -