re-plotting of data on same GUI axes in matlab

333 views Asked by At

I am working with GUI in matlab and I have one axes to plot the data. I want to keep track what I have already plotted in order to re-plot it if needed on same axes and for this purpose, I have list box which holds names of data sets which I have plotted. I am trying to find appropriate way to select the name of data set in list box and re-plot the data set on axes. I am setting some properties of axes while plotting, so I do not not want to perform the re-plotting operation, instead, I want re-use the handle (of some kind) to get the plot data again.

I have some experience of using figure handle to get figure by providing its handle but I am looking something similar for plotting in axes.

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)
1

There are 1 answers

1
Dev-iL On BEST ANSWER

Here's a basic example on how you can do this with 3 plots (save this code as a file and run):

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

Is this what you wanted?