?? zuihou.m
字號:
function varargout = zuihou( varargin )
% this module edit the parameters .
% February 2004
% $Revision: 1.00 $
if (nargin == 0) | isstruct( varargin{1} ) % LAUNCH GUI
if nargin == 1
T_SimulationData = varargin{1} ;
else
T_SimulationData = [] ;
end
% find if have the same figure, and close it .
OldFigure = findobj( 'type', 'figure', 'Tag', 'zuihou' ) ;
if ishandle( OldFigure )
close( OldFigure ) ;
end
% generate a new figure .
FigureHandle = figure( 'Visible', 'off' ) ;
set( FigureHandle, 'Units' , 'pixels', 'Position', [150 150 500 300], ...
'Name', 'T型自卸汽車優化分析程序', ...
'Tag', 'zuihou', ...
'FileName' , '' ,...
'MenuBar' , 'none' ,...
'NumberTitle' , 'off' ,...
'Resize', 'off', ...
'windowstyle', 'normal', ...
'Visible', 'off' ) ;
% generate the menu .
generate_MenuContent( FigureHandle ) ;
% generate the uicontrols .
generate_FigureContent( FigureHandle ) ;
% save the T_SimulationData .
setappdata( FigureHandle, 'T_SimulationData', T_SimulationData ) ;
% display the figure .
movegui( FigureHandle, 'center' ) ;
% set( findobj( FigureHandle, 'Type', 'uicontrol' ), 'Units', 'normalized' ) ;
set( FigureHandle, 'Visible', 'on' ) ;
% init the data .
init_FigureContent( FigureHandle ) ;
if nargout > 0
varargout{1} = FigureHandle;
end
elseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK
global SET_DEBUG_VALUE_IN_SIMULATOR ;
if isempty( SET_DEBUG_VALUE_IN_SIMULATOR ) | ~isnumeric( SET_DEBUG_VALUE_IN_SIMULATOR )
SET_DEBUG_VALUE_IN_SIMULATOR = 0 ;
else
end
if SET_DEBUG_VALUE_IN_SIMULATOR == 1 ;
if (nargout)
[varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard
else
feval(varargin{:}); % FEVAL switchyard
end
else
try
if (nargout)
[varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard
else
feval(varargin{:}); % FEVAL switchyard
end
catch
disp(lasterr);
end
end
end
% ------------------------------------------------------------
function generate_MenuContent( FigureHandle ) ;
% generate the file menu .
% ------------------------------------------------------------
MenuHandle = uimenu( 'Parent', FigureHandle, 'Label', '文件(&F)' ) ;
% define the parameters of the menus .
MenuLabel = { '打開(&O)'; '退出(&E)' } ;
% add Polygon at 2003.10.13 .
MenuTag = { 'MenuOpenResult'; 'MenuClose' } ;
MenuCallback = { ['T_youhua( ''MenuOpenHistory_Callback'', gcbf)']; ...
['close all;'] } ;
SeparatorGroup = { 'off'; 'on' } ;
% generate the uimenus of file .
for num = 1: length( MenuTag )
% for num = 3
UimenuHandle(num) = uimenu( MenuHandle ) ;
set( UimenuHandle(num), 'Tag' , MenuTag{num} , ...
'Callback' , MenuCallback{num} , ...
'Label' , MenuLabel{num} , ...
'Separator', SeparatorGroup{num} ) ;
end
% generate the parameter menu .
% ------------------------------------------------------------
MenuHandle = uimenu( FigureHandle, 'Label', '參數(&P)' ) ;
% define the parameters of the menus .
MenuLabel = { '導入(&L)'; '保存(&E)' } ;
% add Polygon at 2003.10.13 .
MenuTag = { 'MenuLoadData'; 'MenuSaveData' } ;
MenuCallback = { ...
['zuihou( ''LoadData_Callback'', gcbo)']; ...
['zuihou( ''SaveData_Callback'', gcbo)']; } ;
SeparatorGroup = { 'off'; 'on' } ;
% generate the uimenus of file .
for num = 1: length( MenuTag )
UimenuHandle(num) = uimenu( MenuHandle ) ;
set( UimenuHandle(num), 'Tag' , MenuTag{num} , ...
'Callback' , MenuCallback{num} , ...
'Label' , MenuLabel{num} , ...
'Separator', SeparatorGroup{num} ) ;
end
% generate the parameter menu .
% ------------------------------------------------------------
MenuHandle = uimenu( FigureHandle, 'Label', '幫助(&H)', 'Enable', 'on' ) ;
% define the parameters of the menus .
MenuLabel = { '幫助(&P)'; '演示(&D)'; '關于(&A)';'時鐘(&S)' } ;
% add Polygon at 2003.10.13 .
MenuTag = { 'MenuHelp'; 'MenuDemo'; 'MenuAbout';'shijian' } ;
MenuCallback = { ...
['T_youhua( ''MenuHelp_Callback'', gcbo)']; ...
['T_youhua( ''MenuDemo_Callback'', gcbo)']; ...
['T_youhua( ''MenuAbout_Callback'', gcbo)'];...
['T_youhua( ''shizhong'', gcbo)']} ;
SeparatorGroup = { 'off'; 'on'; 'on'; 'on' } ;
% generate the uimenus of file .
for num = 1: length( MenuTag )
UimenuHandle(num) = uimenu( MenuHandle ) ;
set( UimenuHandle(num), 'Tag' , MenuTag{num} , ...
'Callback' , MenuCallback{num} , ...
'Label' , MenuLabel{num} , ...
'Separator', SeparatorGroup{num} ) ;
end
% ------------------------------------------------------------
function generate_FigureContent( FigureHandle )
% generate the uicontrols .
% init the variables .
FigureWidth = 700 ;
FigureHeight = 500 ;
TabSpace = 10 ;
TextHeight = 22 ;
ChangeYPos = 30 ;
% reset the figure's size .
set( FigureHandle, 'Units', 'pixels', ...
'Position', [150 150 FigureWidth FigureHeight], ...
'DoubleBuffer', 'on' ) ;
% generate the axes to plot lines .
AxesHandle = axes( 'Parent', FigureHandle, 'Units' , 'normalized' , ...
'Position', [0 0 1 1], 'Visible', 'off', ...
'Xlim', [0 FigureWidth], 'Ylim', [0 FigureHeight] ) ;
% get the color of the figure .
FigureColor = get( FigureHandle, 'Color' ) ;
% reset the default value of the uicontrols .
set(FigureHandle,'defaultuicontrolunits','normalized');
set(FigureHandle,'defaultuicontrolfontname','隸書');
set(FigureHandle,'defaultuicontrolBackgroundColor', FigureColor );
TitleXPos = TabSpace ;
TitleWidth = FigureWidth - TabSpace * 1.5 ;
TitleHeight = 25 ;
TitleYPos = FigureHeight - TitleHeight - TabSpace * 1 ;
TitlePosition = [TitleXPos TitleYPos TitleWidth TitleHeight] ;
% com_BackgroundFrame(AxesHandle, Frame1Position ) ;
Titlehandle = uicontrol(FigureHandle,'style','text', 'unit','pixels',...
'position',TitlePosition,'horizontal','center',...
'string', 'T型自卸汽車優化軟件最終結果', 'fontsize',18 );
% define the first frame .
FrameXPos = TabSpace * 2 +30;
FrameWidth = (FigureWidth - TabSpace * 6) * 0.5+200 ;
FrameHeight = 180 ;
FrameYPos = TitlePosition(2) - FrameHeight - TabSpace * 2 ;
Frame1Position = [FrameXPos FrameYPos FrameWidth FrameHeight] ;
% generate a frame .
TitleHandle = uicontrol(FigureHandle,'style','frame', 'Units','pixels',...
'position',Frame1Position );
TextXPos = Frame1Position(1) + 15 ;
TextYPos = Frame1Position(2) + Frame1Position(4) - 12 ;
TextWidth = 80 ;
TextPosition = [TextXPos TextYPos TextWidth TextHeight] ;
SubtitleHandle = uicontrol(FigureHandle, 'Style','text', 'Units','pixels',...
'position',TextPosition,'Horizontal','center',...
'string', '初始油壓', 'fontsize',13 );
TextXPos = Frame1Position(1) + 15 +20;
TextYPos = Frame1Position(2) + Frame1Position(4) - 70;
TextWidth = 450 ;
TextPosition = [TextXPos TextYPos TextWidth 40] ;
SubtitleHandle = uicontrol(FigureHandle, 'Style','text', 'Units','pixels',...
'position',TextPosition,'Horizontal','left',...
'string', '優化前后的初始油壓比較', 'fontsize',13 );
text1 = uicontrol(FigureHandle, 'Style','text', 'Units','pixels',...
'position',[100 330 80 30],'Horizontal','left',...
'string', '優化前', 'fontsize',13 );
edit1 = uicontrol(FigureHandle, 'Style', 'edit', 'Units','pixels',...
'position', [180 330 80 30], 'Horizontal','center', 'BackgroundColor', [1 1 1], ...
'Tag','edit1' , ...
'String', 0, 'FontSize',11);
text2 = uicontrol(FigureHandle, 'Style','text', 'Units','pixels',...
'position',[300 330 80 30],'Horizontal','left',...
'string', '優化后', 'fontsize',13 );
edit2 = uicontrol(FigureHandle, 'Style', 'edit', 'Units','pixels',...
'position', [380 330 80 30], 'Horizontal','center', 'BackgroundColor', [1 1 1], ...
'Tag','edit2' , ...
'String', 0, 'FontSize',11);
text3 = uicontrol(FigureHandle, 'Style','text', 'Units','pixels',...
'position',[100 280 120 30],'Horizontal','left',...
'string', '優化后提高', 'fontsize',13 );
text3 = uicontrol(FigureHandle, 'Style','text', 'Units','pixels',...
'position',[350 280 120 30],'Horizontal','left',...
'string', '%', 'fontsize',13 );
edit3 = uicontrol(FigureHandle, 'Style', 'edit', 'Units','pixels',...
'position', [250 280 80 30], 'Horizontal','center', 'BackgroundColor', [1 1 1], ...
'Tag','edit3' , ...
'String', 0, 'FontSize',11);
FrameXPos = TabSpace * 2 +30;
FrameWidth = (FigureWidth - TabSpace * 6) * 0.5+200 ;
FrameHeight = 180 ;
FrameYPos = TitlePosition(2) - FrameHeight - TabSpace * 2-210 ;
Frame1Position = [FrameXPos FrameYPos FrameWidth FrameHeight] ;
% generate a frame .
TitleHandle = uicontrol(FigureHandle,'style','frame', 'Units','pixels',...
'position',Frame1Position );
TextXPos = Frame1Position(1) + 15 ;
TextYPos = Frame1Position(2) + Frame1Position(4) - 12 ;
TextWidth = 150 ;
TextPosition = [TextXPos TextYPos TextWidth TextHeight] ;
SubtitleHandle = uicontrol(FigureHandle, 'Style','text', 'Units','pixels',...
'position',TextPosition,'Horizontal','center',...
'string', '設計變量優化結果', 'fontsize',13 );
TextXPos = Frame1Position(1) + 15 +20;
TextYPos = Frame1Position(2) + Frame1Position(4) - 150;
TextWidth = 450 ;
TextPosition = [TextXPos TextYPos TextWidth 120] ;
SubtitleHandle = uicontrol(FigureHandle, 'Style','text', 'Units','pixels',...
'position',TextPosition,'Horizontal','left',...
'string', '基于遺傳算法所得到的設計變量優化結果', 'fontsize',13 );
Text4 = uicontrol(FigureHandle,'style','text', 'Units','pixels',...
'position',[80 90 80 30] ,'Horizontal','center',...
'string', '設計變量', 'fontsize',13 );
edit4 = uicontrol(FigureHandle, 'Style', 'edit', 'Units','pixels',...
'position', [200 90 300 25], 'Horizontal','center', 'BackgroundColor', [1 1 1], ...
'Tag','edit4' , ...
'String', 0, 'FontSize',11);
% define the parameters of the buttons .
ButtonString = { '上一步'; '導入'; '保存'; '結束' } ;
ButtonTag = { 'PreviousButton'; 'LoadButton'; 'SaveButton'; 'NextButton' } ;
ButtonCallback = { ['zuihou(''PreviousButton_Callback'',gcbo)']; ...
['zuihou(''LoadData_Callback'',gcbo)']; ...
['zuihou(''SaveData_Callback'',gcbo)']; ...
['zuihou(''NextButton_Callback'',gcbo)'] } ;
ButtonWidth = 80 ;
ButtonHeight = 25 ;
ButtonXPos = FigureWidth - ButtonWidth * 4 - TabSpace * 6 ;
ButtonYPos = TabSpace * 2 ;;
ButtonPosition = [ButtonXPos ButtonYPos ButtonWidth ButtonHeight] ;
for num = 1: 4
TempButtonPosition = ButtonPosition ;
TempButtonPosition(1) = TempButtonPosition(1) + (num - 1) * (ButtonWidth + TabSpace) ;
% generate the pushbutton: OK .
ButtonHandle = uicontrol( 'Parent', FigureHandle, 'Units', 'Pixels', 'Position', TempButtonPosition, ...
'Style', 'pushbutton', 'Tag',ButtonTag{num}, 'string', ButtonString{num}, 'Fontsize',12, ...
'Callback', ButtonCallback{num} ) ;
end
handles = guihandles( FigureHandle ) ;
guidata( FigureHandle, handles ) ;
% --------------------------------------------------------------------------
function init_FigureContent( h )
handles = guidata( h ) ;
% get the T_SimulationData .
T_SimulationData = getappdata( handles.zuihou, 'T_SimulationData' ) ;
if isempty( T_SimulationData )
T_SimulationData = T_youhua( 'Get_DefaultT_SimulationData' ) ;
% save the data .
setappdata( handles.zuihou, 'T_SimulationData', T_SimulationData ) ;
end
xx = T_SimulationData.Position(1).P;
yy = T_SimulationData.Position_yh(1).P;
zz = 100*(xx-yy)/xx;
pp = T_SimulationData.x;
set(handles.edit1,'string',xx);
set(handles.edit2,'string',yy);
set(handles.edit3,'string',zz);
set(handles.edit4,'string',num2str(pp));
%---------------------------------------------------------------
function LoadData_Callback( h )
handles = guidata( h ) ;
PromptString = '選擇數據文件.' ;
WarningString1 = '文件格式出錯。 ' ;
WarningString2 = '選擇的文件不是正確的數據文件。 ' ;
[ FileName , PathName ] = uigetfile( {'*.mat','數據文件(*.mat)'}, PromptString ) ;
if FileName == 0
return ;
else
[TempPathName, FileName, FileTypeName, Version] = fileparts( FileName ) ;
if ~strcmp( FileTypeName, '.mat' ) ;
warndlg( WarningString1, '警告', 'modal' ) ;
return ;
end
SaveFile = fullfile( PathName, [FileName, FileTypeName, Version] ) ;
end
T_SimulationData = [] ;
try
load( SaveFile, 'T_SimulationData' ) ;
catch
end
if isempty( T_SimulationData ) | ~isstruct( T_SimulationData );
warndlg( WarningString1, '警告', 'modal' ) ;
return ;
end
% save the data .
setappdata( handles.zuihou, 'T_SimulationData', T_SimulationData ) ;
% display the new data .
init_FigureContent( h ) ;
% --------------------------------------------------------------------------
function SaveData_Callback( h )
handles = guidata( h ) ;
% get the T_SimulationData .
T_SimulationData = getappdata( handles.zuihou, 'T_SimulationData' ) ;
x = T_SimulationData.x;
PromptString = '保存數據文件.' ;
MessageString = '保存數據文件成功。 ' ;
[ FileName , PathName ] = uiputfile( {'*.mat','數據文件(*.mat)'}, PromptString ) ;
if FileName == 0
return ;
else
[TempPathName, FileName, FileTypeName, Version] = fileparts( FileName ) ;
if ~strcmp( FileTypeName, '.mat' ) ;
FileTypeName = '.mat' ;
else
end
SaveFile = fullfile( PathName, [FileName, FileTypeName, Version] ) ;
end
% save the result file .
save( SaveFile, 'x' ) ;
msgbox( MessageString ) ;
% --------------------------------------------------------------------------
function PreviousButton_Callback( h )
handles = guidata( h ) ;
% get the T_SimulationData .
T_SimulationData = getappdata( handles.zuihou, 'T_SimulationData' ) ;
% return the wizard figure .
xianshi( T_SimulationData ) ;
% close the current figure .
pause(0) ;
close( handles.zuihou ) ;
% --------------------------------------------------------------------------
function NextButton_Callback( h )
handles = guidata( h ) ;
pause(0) ;
close( handles.zuihou ) ;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -