📄 gui_callback.m
字号:
function GUI_Callback()
Action = get(gcbo, 'Tag');
switch(Action)
case 'RescaleCurrent',
%Test to see whether this set of axes is a colorbar
ImgHndl = findobj(gca, 'type', 'image', 'tag', 'TMW_COLORBAR');
if ~isempty(ImgHndl)
ud = get(gca,'userdata');
axes(ud.PlotHandle);
end
AxDlg = GUI_AxLimDlg('Limits for current axes', [1 1]);
uiwait(AxDlg);
case {'SaveTIFPortrait', 'SaveTIFLandscape'},
%Set up the paper position properties appropriate for the specified orientation
ThisFig = gcbf;
switch Action
case 'SaveTIFPortrait',
set(ThisFig, ...
'PaperType', 'A4', ...
'PaperUnits', 'centimeters', ...
'PaperOrientation', 'portrait', ...
'PaperPosition', [3.17, 16 ,13.5, 10.125] ...
);
case 'SaveTIFLandscape',
set(ThisFig, ...
'PaperType', 'A4', ...
'PaperUnits', 'centimeters', ...
'PaperOrientation', 'landscape', ...
'PaperPosition', [2.5, 3.17, 24, 13.625] ...
);
%'PaperPosition', [5.072, 3.17, 18.166667, 13.625] ...
end
if exist('GUI_Defaults.m', 'file')
DfltInfo = GUI_Defaults;
Home = pwd;
cd(DfltInfo.ImageDir);
SetDflt = 1;
else
SetDflt = 0;
end
[FName, Path] = uiputfile('*.tif', 'Save figure to:');
if SetDflt
cd(Home);
end
if FName ~= 0
HFig = gcbf;
%print('-dtiff', '-fHFig', [Path FName]);
print('-dtiff', [Path FName]);
end
case 'RescaleAll',
AxesHandles = findobj(gcbf, 'Type', 'axes');
NAx = length(AxesHandles);
GotNewVals = 0;
AxArr = [];
for IAx = 1:NAx
%Test to see whether this set of axes is a colorbar
ImgHndl = findobj(AxesHandles(IAx), 'type', 'image', 'tag', 'TMW_COLORBAR');
%don't rescale the colorbars
if isempty(ImgHndl)
AxArr = [AxArr AxesHandles(IAx)];
end
end
if ~isempty(AxArr)
AxDlg = GUI_AxLimDlg('Limits for all axes', [1 1], AxArr);
uiwait(AxDlg);
end
case 'Zoom',
CtrlType = get(gcbo, 'Type');
switch CtrlType
case 'uimenu',
if strcmp(get(gcbo, 'Checked'), 'on')
ZoomState = 0;
set(gcbo, 'Checked', 'off');
else
ZoomState = 1;
set(gcbo, 'Checked', 'on');
end
case 'uicontrol',
ZoomState = get(gcbo, 'Value');
end
if ZoomState;
zoom on;
else
zoom off;
end
case 'Rotate3D',
CtrlType = get(gcbo, 'Type');
switch CtrlType
case 'uimenu',
if strcmp(get(gcbo, 'Checked'), 'on')
RotState = 0;
set(gcbo, 'Checked', 'off');
else
RotState = 1;
set(gcbo, 'Checked', 'on');
end
case 'uicontrol',
RotState = get(gcbo, 'Value');
end
if RotState;
rotate3d on;
else
rotate3d off;
end
case {'ColourRescaleAll', 'ColourRescaleCurrent'},
Current = caxis;
prompt={'Enter new minimum value:','Enter new maximum value:'};
def={num2str(Current(1)), num2str(Current(2))};
ThisTitle='Colour axis scaling';
lineNo=1;
OK = 0;
Cancel = 0;
while ~OK & ~Cancel
Answer=inputdlg(prompt,ThisTitle,lineNo,def);
if isempty(Answer)
Cancel = 1;
else
Min = str2num(Answer{1});
Max = str2num(Answer{2});
if ~isempty(Min) & ~isempty(Max)
OK = 1;
else
if isempty(Min)
Warn = warndlg('Invalid minimum value', '');
uiwait(Warn);
end
if isempty(Max)
Warn = warndlg('Invalid maximum value', '');
uiwait(Warn);
end
end
end
end
if OK
switch Action
case 'ColourRescaleAll',
AxesHandles = findobj(gcbf, 'Type', 'axes');
NAx = length(AxesHandles);
for IAx = 1:NAx;
axes(AxesHandles(IAx));
caxis([Min Max]);
%Test to see whether this set of axes is a colorbar
ImgHndl = findobj(gca, 'type', 'image', 'tag', 'TMW_COLORBAR');
if ~isempty(ImgHndl)
%Define the properties to be maintained by the new colorbar
%save axis properties
Properties = SaveAxisProperties(gca);
%switch back to the axes that defined this colorbar
ud = get(gca,'userdata');
axes(ud.PlotHandle);
caxis([Min Max]); %Make sure the parent axes have the new colour scheme before calling colorbar
h = colorbar; %re-draw colorbar
%restore the axis and label properties
RestoreAxisProperties(h, Properties);
end
end
case 'ColourRescaleCurrent',
%Test to see whether this set of axes is a colorbar
ImgHndl = findobj(gca, 'type', 'image', 'tag', 'TMW_COLORBAR');
if isempty(ImgHndl)
%Not a colorbar
DefAx = gca; %Defining axes
%find the colorbar axes that has the current axes as the defining axes
caxis([Min Max]);
AllCBarImg = findobj(gcf, 'type', 'image', 'tag', 'TMW_COLORBAR');
GotCBar = 0;
for IImg = 1:length(AllCBarImg)
CB = get(AllCBarImg(IImg), 'Parent'); %The colorbar is the parent of the image
UData = get(CB, 'userdata');
if UData.PlotHandle == DefAx
ThisColorBar = CB;
GotCBar = 1;
end
end
else
ThisColorBar = gca;
UData = get(ThisColorBar, 'userdata');
DefAx = UData.PlotHandle;
GotCBar = 1;
end
if GotCBar
Prop = SaveAxisProperties(ThisColorBar);
axes(DefAx);
caxis([Min Max]);
h = colorbar; %re-draw colorbar
%restore the axis and label properties
RestoreAxisProperties(h, Prop);
end
end
end
case 'GInput',
Done = 0;
while ~Done
figure(gcbf);
[X, Y, Button] = GUI_ginput(1);
Status = GUI_GInputQuery({['X = ', num2str(X, 9)], ['Y = ', num2str(Y, 9)]});
Done = ~Status;
end
if strcmp(get(gcbo, 'type'), 'uicontrol')
set(gcbo, 'value', 0);
end
case 'DeltaValues',
Done = 0;
while ~Done
figure(gcbf);
[X, Y, Button] = GUI_ginput(2);
Status = GUI_GInputQuery({['Delta X = ', num2str(diff(X), 9)], ...
['Delta Y = ', num2str(diff(Y), 9)], ...
['Distance = ', num2str(sqrt(diff(X)^2 + diff(Y)^2))]});
Done = ~Status;
end
if strcmp(get(gcbo, 'type'), 'uicontrol')
set(gcbo, 'value', 0);
end
case 'FontEverythingAll',
AxesHandles = findobj(gcbf, 'Type', 'axes');
for IAx = 1:length(AxesHandles);
if IAx == 1
NewFont = uisetfont(AxesHandles(IAx));
else
set(AxesHandles(IAx), NewFont);
end
HArr = get(AxesHandles(IAx), {'xlabel', 'ylabel', 'zlabel', 'title'});
for ILab = 1:length(HArr)
set(HArr{ILab}, NewFont);
end
end
case 'FontAxesAll',
AxesHandles = findobj(gcbf, 'Type', 'axes');
for IAx = 1:length(AxesHandles);
if IAx == 1
NewFont = uisetfont(AxesHandles(IAx));
else
set(AxesHandles(IAx), NewFont);
end
end
case 'FontLabelsAll',
AxesHandles = findobj(gcbf, 'Type', 'axes');
for IAx = 1:length(AxesHandles);
HArr = get(AxesHandles(IAx), {'xlabel', 'ylabel', 'zlabel'});
for ILab = 1:length(HArr)
if (IAx == 1) & (ILab == 1)
NewFont = uisetfont(HArr{ILab});
else
set(HArr{ILab}, NewFont);
end
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -