Using an axes handle as an input for a function
10 views (last 30 days)
Show older comments
Hi everyone,
I'm working on a MATLAB app which does some plotting, and to simplify the code, I was trrying to generalise my plotting function so that I can tell it whether to plot everything on axes A or on axes B.
Essentially I have a preview window where you can add options to the plot which is then shown in "app.smallpax", but then I switch to a saving window where I want the exact same plot, with all the options you selected in the preview, but just larger and with a save button.
Therefore, I want to plot the same thing in 2 different places, but maintain also options for grids, axes, colorbars etc which don't come packaged in the graphics object porperties. I have looked into copyobj but it does not transfer colorbars and grid settings, which leads to a lot of duplicate code and logic to reapply them there again, due to how the option buttons and tickboxes are coded.
This below is the function I'm trying to generalise. I added a "target" handle which would point to either a small polar axes "app.smallpax" (for the preview window) and a big one, "app.bigpax" (for the saving window).
function PlotPolarCoordinates(app, target)
delete(target) % remove any previous graph
if strcmp(target,'app.smallpax') ==1 % check what the target is and assign it to the corresponding UI panel
app.smallpax = polaraxes(app.SmallFingerprintPlotPanel);
elseif strcmp(target,'app.bigpax') ==1 % check what the target is and assign it to the corresponding UI panel
app.bigpax = polaraxes(app.BigFingerprintPlotPanel);
end
% plot the polar scatter graph on the target axes
app.fingerprint_plot = polarscatter(target,app.theta - app.angle*pi/180,app.rho,1,app.data_processed(:,app.AxisPlottingDropDown.Value),'.');
% set the target axes and any grid on top of the plot
set(target,'Layer','top','LineWidth',1,'FontWeight','bold','GridAlpha',1,'MinorGridAlpha',1,'RColor',[0.41176 0.41176 0.41176],'ThetaColor',[0.41176 0.41176 0.41176])
colormap(target,app.ColorMapDropDown.Value);
clim(target,[app.cmin,app.cmax]);
end
I assumed I could just place it within the set , clim or colomp commands just as a variable given that I am passing it as a string (i.e.
app.PlotPolarCoordinates('app.smallpax')
%or
app.app.PlotPolarCoordinates('app.bigpax')
This is essentially a consequence of a lot of smaller issues and I have a feeling that I'm wrapping myself up in a spaghetti code.
Any help on the best way of doing this would be greatly welcome.
Thanks!
Answers (0)
See Also
Categories
Find more on Graphics Performance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!