MATLAB Answers

# Plot specific UIAxes command in a function

22 views (last 30 days)
Hello,
I am coding a function to plot scatterplot in App Designer. I want my function to take as an input the UIAxes in which I want to plot.
So far I'm nowhere near a solution.
My function:
function bplot(~,axes,x,y) %axes would be UIAxes1 ; UIAxes2 ; ...
for i = 1:size(x,2) %the for loop to plot specific characteristics for each point
scatter(axes,x(i),y(i)); % Here editor alert: "Specify a UIAxes handle as first argument."
end
The progam runs but doesn't give anything back.
Thanking you for your help!
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Answers (2)

Katie on 23 Oct 2019
Hi! The code below shows two different examples of taking a UIAxes object as an input to a function. I'm unclear as to whether you want to plot a bunch of scatter points to one UIAxes object or if you want to plot a single point to each of multiple UI Axes objects, so here are solutions to both:
Situation 1:
I made a small test app to work through your function. I have this setup so that it runs the bplot function when you press the button and all the scatter points are plotted on this one specified UIAxes object. See the code pieces below: %push button callback
function ButtonPushed(app, event)
%I'm setting x and y here because I'm not sure where you're getting them
x=1:5;
y=1:5;
bplot(app, app.UIAxes, x, y);
end
%private function to plot on specified UIAxes
function results = bplot(app, axisObj, x, y)
scatter(axisObj, x, y); %plot all the xy pairs of points on the single UIAxes object in the app
end
Situation 2:
When you press the button, one scatter point is plotted on the first UIAxes and the next scatter point is plotted on the second UIAxes. %create a private property to store your list of UIAxes objects you want to plot to
properties (Access = private)
AxesStorage % Storage of UIAxes objects
end
%initialize the AxesStorage property in the startup callback function
function startupFcn(app)
app.AxesStorage={app.UIAxes, app.UIAxes2};
end
% Button pushed function: Button
function ButtonPushed(app, event)
x=1:2;
y=1:2;
%make sure the length of your x vector is the same as the number of UIAxes objects
%because you are looping through the indicies of x in bplot()
bplot(app, app.AxesStorage, x, y);
end
function results = bplot(app, axisObj, x, y)
for i=1:length(x)
scatter(axisObj{i}, x(i), y(i));
end
end
If you want to plot all the scatter points on both UI Axes you could change the bplot function to be the following:
function results = bplot(app, axisObj, x, y)
for i=1:length(axisObj)
scatter(axisObj{i}, x, y); %I changed x to be x=1:3 and y to be y=1:3 for this version of the function
end
end Hope this helps!
##### 1 CommentShowHide None
yvesvincent abgrall on 24 Oct 2019
Thank you very much Katelyn for your answer! It's working very well!
Since I published this question, the problem has evolved.

Sign in to comment.

yvesvincent abgrall on 24 Oct 2019
I want to have a Bubble plot. I found this function on the File Exchange: https://nl.mathworks.com/matlabcentral/fileexchange/48005-bubbleplot-multidimensional-scatter-plots
This function is very complex to me, I don't understand how it is plotting.
Since I don't understand the function I'm not able to modify it in order to plot in the UIAxes I want.
I found a workaround though:
set(bubbleplot(a,b,[],c),'Parent', app.UIAxes2); %with a b and c some arrays
The problem is yet partially solved: I can get the code the plot it in the UIAxes I want but I also get an empty figure popping up (the classic plot type of figure).
Do you know how to only get it to show the plot in the UIAxes without creating a new figure?
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

R2019a

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!