在 matlab 中的相同 GUI 轴上重新绘制数据

re-plotting of data on same GUI axes in matlab

我在 matlab 中使用 GUI,我有一个轴来绘制数据。我想跟踪我已经绘制的内容,以便在需要时在同一轴上重新绘制它,为此,我有一个列表框,其中包含我绘制的数据集的名称。我正在尝试找到适当的方法来 select 列表框中的数据集名称,并在轴上重新绘制数据集。我在绘图时设置了轴的一些属性,所以我不想执行重新绘图操作,相反,我想重新使用句柄(某种)再次获取绘图数据。

我有一些使用图形句柄通过提供图形句柄来获取图形的经验,但我正在寻找类似的东西来在轴上绘图。

f1  = figure 
plot ([0:0.1:2*pi] , cos ([0:0.1:2*pi]))
f2  = figure 
plot ([0:0.1:2*pi] , sin([0:0.1:2*pi]))

figure(f1) or figure (f2)

这是一个基本示例,说明如何使用 3 个绘图(将此代码另存为文件并 运行):

function Example
%% // Init
close all;
%% // Example figure
figure(201);
h(1) = ezplot('sin(x)'); hold on; h(2) = ezplot('cos(x)'); h(3) = ezplot('tan(x)');

%% // Create a UI control
hDrop = uicontrol(201,...
    'FontUnits',get(0,'defaultuicontrolFontUnits'),...
    'Style','popupmenu',...
    'Units','normalized',...
    'Position',[0.729,0.879,0.134,0.027],...
    'Callback',@dropdown_callback,...
    'String',{'Plot1';'Plot2';'Plot3'},...
    'Value',1); %// default plot

handles = struct('hPlots',h,'hDrop',hDrop); %// Create a "handles" structure
guidata(201,handles); %// Associate the handles structure with the figure
hide_all_besides_selected(1); %// Unhide only the default

function dropdown_callback(hObj,~)
    hide_all_besides_selected(get(hObj,'Value'));

function hide_all_besides_selected(selectedVal)
    handles = guidata(gcf); %// Retrieve the handles
    for ind1=1:numel(handles.hPlots) %// Hide everything
        set(handles.hPlots,'Visible','off');
    end
    set(handles.hPlots(selectedVal),'Visible','on'); %// Unhide the relevant plot

这是你想要的吗?