📄 exportps2wsdlg.m
字号:
tempstruct.Aineq = aInEq;
tempstruct.Bineq = bInEq;
tempstruct.Aeq = aEq;
tempstruct.Beq = bEq;
if randchoice
tempstruct.randstate = randstate;
tempstruct.randnstate = randnstate;
end
%remove special gui outputfcn which is the first in the list
if ~isempty(options.OutputFcns)
temp = options.OutputFcns{1};
temp = temp{1};
if strcmp(func2str(temp), 'psearchtooloutput')
options.OutputFcns(1) = [];
end
end
if isempty(options.OutputFcns)
options.OutputFcns = [];
end
if get(cb{CB_RESTART}, 'Value') == 1
tempstruct.X0=x;
end
tempstruct.options=options;
assignin('base', get(e{CB_PROBLEM}, 'String'), tempstruct);
end
if get(cb{CB_OPTION}, 'Value') == 1
options = psguiReadHashTable(model);
%remove special gui outputfcn which is the first in the list
if ~isempty(options.OutputFcns)
temp = options.OutputFcns{1};
temp = temp{1};
if strcmp(func2str(temp), 'psearchtooloutput')
options.OutputFcns(1) = [];
end
end
if isempty(options.OutputFcns)
options.OutputFcns = [];
end
assignin('base', get(e{CB_OPTION}, 'String'), options);
end
if get(cb{CB_RESULTS}, 'Value') == 1
tempstruct = struct;
tempstruct.x = x;
tempstruct.fval = fval;
tempstruct.exitmessage = exitmessage;
tempstruct.output = output;
assignin('base', get(e{CB_RESULTS}, 'String'), tempstruct);
end
if length(varnames) == 1
msg = sprintf('The variable ''%s'' has been created in the current workspace.', varnames{1});
elseif length(varnames) == 2
msg = sprintf('The variables ''%s'' and ''%s'' have been created in the current workspace.', varnames{1}, varnames{2});
elseif length(varnames) == 3
msg = sprintf('The variables ''%s'', ''%s'' and ''%s'' have been created in the current workspace.', varnames{1}, varnames{2}, varnames{3});
else %shouldn't get here
msg='';
end
disp(msg);
delete(dialog);
else
errordlg('Names must be unique', 'Invalid Names');
end
%----------------------------------------------------------------------------
function CancelCallback(obj, eventdata, dialog)
delete(dialog);
%----------------------------------------------------------------------------
function KeyPressCallback(obj, eventdata, dialog, cb, e, model, x, fval, ...
exitmessage,output, objFunction, startPoint, lBnds, uBnds, aInEq, ...
bInEq, aEq, bEq, randstate, randnstate, randchoice)
asciiVal = get(dialog, 'CurrentCharacter');
if ~isempty(asciiVal)
% space bar or return is the "same" as OK
if (asciiVal==32 || asciiVal==13)
OKCallback(obj, eventdata, dialog, cb, e, model, x, fval, ...
exitmessage,output,objFunction, startPoint, lBnds, ...
uBnds, aInEq, bInEq, aEq, bEq, randstate, randnstate, ...
randchoice);
elseif (asciiVal == 27) % escape is the "same" as Cancel
delete(dialog);
end
end
%----------------------------------------------------------------------------
function [cb, e] = layoutDialog(hDlg, okBut, cancelBut, checkboxLabels, ...
variableNames, disableFields, objFunction, startPoint)
EXTENT_WIDTH_INDEX = 3; % width is the third argument of extent
POS_X_INDEX = 1;
POS_Y_INDEX = 2;
POS_WIDTH_INDEX = 3;
POS_HEIGHT_INDEX = 4;
CONTROL_SPACING = 5;
EDIT_WIDTH = 90;
CHECK_BOX_WIDTH = 20;
DEFAULT_INDENT = 20;
CB_PROBLEM = 1;
CB_OPTION = 3;
CB_RESTART = 2;
CB_RESULTS = 4;
okPos = get(okBut, 'Position');
cancelPos = get(cancelBut, 'Position');
longestCBExtent = 0;
ypos = okPos(POS_HEIGHT_INDEX) + okPos(POS_Y_INDEX)+ 2*CONTROL_SPACING;
cb = cell(4, 1);
e = cell(4, 1);
for i = 4:-1:1
cb{i} = uicontrol(hDlg, 'Style', 'checkbox', 'String', ...
checkboxLabels{i});
check_pos = get(cb{i}, 'Position');
check_pos(POS_Y_INDEX) = ypos;
extent = get(cb{i}, 'Extent');
width = extent(EXTENT_WIDTH_INDEX);
check_pos(POS_WIDTH_INDEX) = width + CHECK_BOX_WIDTH;
set(cb{i}, 'Position', check_pos);
if (i==CB_RESTART) %indent 2nd line a little and don't add a edit field;
check_pos(POS_X_INDEX) = check_pos(POS_X_INDEX) + CHECK_BOX_WIDTH;
set(cb{i}, 'Position', check_pos);
else
e{i} = uicontrol(hDlg, 'Style', 'edit', 'String', variableNames{i}, ...
'BackgroundColor', 'white', ...
'HorizontalAlignment', 'left');
edit_pos = get(e{i}, 'Position');
edit_pos(POS_Y_INDEX) = ypos;
edit_pos(POS_WIDTH_INDEX) = EDIT_WIDTH;
% cursor doesn't seem to appear in default edit height
edit_pos(POS_HEIGHT_INDEX) = edit_pos(POS_HEIGHT_INDEX) + 1;
set(e{i}, 'Position', edit_pos);
end
ypos = ypos + CONTROL_SPACING + edit_pos(POS_HEIGHT_INDEX);
if width > longestCBExtent
longestCBExtent = width;
end
if isempty(objFunction) || isempty(startPoint)
set(cb{CB_PROBLEM}, 'Enable', 'off');
set(e{CB_PROBLEM}, 'Enable', 'off');
set(e{CB_PROBLEM}, 'Backgroundcolor', [0.831373 0.815686 0.784314]);
end
if disableFields
set(cb{CB_RESTART}, 'Enable', 'off');
set(cb{CB_RESULTS}, 'Enable', 'off');
set(e{CB_RESTART}, 'Enable', 'off');
set(e{CB_RESTART}, 'Backgroundcolor', [0.831373 0.815686 0.784314]);
set(e{CB_RESULTS}, 'Enable', 'off');
set(e{CB_RESULTS}, 'Backgroundcolor', [0.831373 0.815686 0.784314]);
if strcmp(get(cb{CB_PROBLEM}, 'Enable'), 'off') % only options is enabled - check it
set(cb{CB_OPTION}, 'Value', 1);
end
end
end
% Position edit boxes
edit_x_pos = check_pos(POS_X_INDEX) + longestCBExtent + CONTROL_SPACING ...
+ CHECK_BOX_WIDTH;
for i = 1:4
edit_pos = get(e{i}, 'Position');
edit_pos(POS_X_INDEX) = edit_x_pos;
set(e{i}, 'Position', edit_pos);
end
h_pos = get(hDlg, 'Position');
h_pos(POS_WIDTH_INDEX) = max(edit_x_pos + edit_pos(POS_WIDTH_INDEX) + ...
CHECK_BOX_WIDTH, okPos(POS_WIDTH_INDEX) + ...
cancelPos(POS_WIDTH_INDEX) + ...
CONTROL_SPACING + (2 * DEFAULT_INDENT));
h_pos(POS_HEIGHT_INDEX) = ypos;
set(hDlg, 'Position', h_pos);
% Make sure it is on-screen
oldu = get(0,'Units');
set(0,'Units','pixels');
screenSize = get(0,'ScreenSize');
set(0,'Units',oldu);
outerPos = get(hDlg,'OuterPosition');
if outerPos(1)+outerPos(3) > screenSize(3)
outerPos(1) = screenSize(3) - outerPos(3);
end
if outerPos(2)+outerPos(4) > screenSize(4)
outerPos(2) = screenSize(4) - outerPos(4);
end
set(hDlg, 'OuterPosition', outerPos);
x_ok = (h_pos(POS_WIDTH_INDEX))/2 - (okPos(POS_WIDTH_INDEX) + ...
CONTROL_SPACING + cancelPos(POS_WIDTH_INDEX))/2;
okPos(POS_X_INDEX) = x_ok;
set(okBut, 'Position', okPos);
cancelPos(POS_X_INDEX) = okPos(POS_X_INDEX) + okPos(POS_WIDTH_INDEX) + ...
CONTROL_SPACING;
set(cancelBut, 'Position', cancelPos);
% Reorder the children so that tabbing makes sense
children = get(hDlg, 'children');
children = flipud(children);
set(hDlg, 'children', children);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -