我不确定我是否以正确的方式进行此操作,但我想要一个在调用时基本上重置 4 个图的函数。我将图存储为handles.distplot1
,handles.distplot2
依此类推,希望有一个下拉菜单来选择轴上显示的图。在几个不同的事件之后我需要重置这些图,所以我自然想把它们扔到一个函数中并避免代码冗余。我希望像这样的功能
function setupDistPlots(hObject, eventdata, handles)
% filler data for surfc
x = [1 2];
z = zeros(2);
% setup blank plots for funtion to work with
a = figure(1); set(a, 'Visible', 'off')
handles.distplot1 = surfc(x, x, z);
b = figure(2); set(b, 'Visible', 'off');
handles.distplot2 = bar(NaN);
c = figure(3); set(c, 'Visible', 'off')
handles.distplot3 = surfc(x, x, z);
d = figure(4); set(d, 'Visible', 'off')
handles.distplot4 = bar(NaN);
guidata(hObject, handles);
我认为它应该按预期工作,但我不知道如何称呼它。在打开功能中,我尝试setupDistPlots(hObject, eventdata, handles)
稍后尝试访问时收到以下错误handles.distplot1
:
Reference to non-existent field 'distplot1'.
Error in tabbedGUI>distanceToggle_Callback (line 212)
distribution(hObject,
handles.distplot1, ...
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in tabbedGUI (line 45)
gui_mainfcn(gui_State, varargin{:});
Error in
@(hObject,eventdata)tabbedGUI('distanceToggle_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback
编辑:另外请指出我可以改进的一切。我在 Matlab 中所做的一切都让人感觉很老套,好像一定有更好的方法。
edit2:打开函数的问题是在调用打开函数setupDistPlots
之前guidata(hObject, handles)
调用。然而,现在当我再次按下按钮调用“setupDistPlots”时,我收到以下错误:
Error using matlab.graphics.primitive.Data/set
Invalid or deleted object.
Error in andrewDistribution (line 45)
set(hplot1, 'xData', x1, 'yData', y1, 'zData', zeros(length(x1)))
Error in tabbedGUI>distanceToggle_Callback (line 200)
distribution(hObject, handles.distplot1, ...
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in tabbedGUI (line 45)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)tabbedGUI('distanceToggle_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback