MATLAB: How to Transfer data from Main gui to another GUI in case , when multiple instances of GUI is used

MATLABmatlab guimultiple instance of guisetappdatasimulink

I have a MATLAB GUI (MAIN GUI) which is used to run a simulation and the results are plotted in a separate GUI (Plotting GUI). I have used setappdata/getappdata meathod to transfer data between the GUI. Additionally user can have multiple instances of the plotting GUI (where results are plotted) to plot different signals. Though I have used setappdata to select the GCF (current figure) in the opening function of the Plotting GUI, the results are getting plotted in different GUI (ex. Results intended to be plotted on plotting GUI 2 are plotted in plotting GUI 1).
How can I ensure that the intended instace of the GUI is selected for plotting of results ?

Best Answer

Sundeepan - I strongly suggest that you don't use eval to evaluate your expressions. Your
id = strcat('hPlot',num2str(l)); % name assigned to each figure
eval(sprintf('%s = PlottingGUI;',id)); % call plotting GUI
seems to be dynamically creating local variables to the multiple instances of the PlottingGUI. But what happens to these variables afterwards? How do you reference them? A better solution would be to create an array of handles to the GUIs like
hPlottingGui = [];
for l = 1:num
hPlottingGui(l) = PlottingGUI;
end
With the above, you will still have all of the handles but they will be stored in an array and so easier to access/manipulate.
With your third piece of code, you state that In Main GUI, the plotting GUI is then called using the following code: which is
for figure_number = 1:num
GenID = strcat('Plot',num2str(figure_number));
GenGUI = getappdata(0,GenID); % collects handle to the plotting gui
g_main = findobj(GenGUI , 'type' , 'axes'); % looks for object of type
axes(g_main);
% etc.
end
But the above iterates over ALL of your Plotting GUIs and not just a particular one. This implies that all of them will be updated. So how do you know when the Main GUI should update the Plotting GUI k?