Plot specific UIAxes command in a function

조회 수: 14 (최근 30일)
yvesvincent abgrall
yvesvincent abgrall 2019년 10월 18일
답변: yvesvincent abgrall 2019년 10월 24일
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."
The progam runs but doesn't give anything back.
Thanking you for your help!

답변 (2개)

Katie 2019년 10월 23일
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
bplot(app, app.UIAxes, x, y);
%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
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
%initialize the AxesStorage property in the startup callback function
function startupFcn(app)
app.AxesStorage={app.UIAxes, app.UIAxes2};
% Button pushed function: Button
function ButtonPushed(app, event)
%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);
function results = bplot(app, axisObj, x, y)
for i=1:length(x)
scatter(axisObj{i}, x(i), y(i));
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
Hope this helps!
  댓글 수: 1
yvesvincent abgrall
yvesvincent abgrall 2019년 10월 24일
Thank you very much Katelyn for your answer! It's working very well!
Since I published this question, the problem has evolved.

댓글을 달려면 로그인하십시오.

yvesvincent abgrall
yvesvincent abgrall 2019년 10월 24일
I want to have a Bubble plot. I found this function on the File Exchange:
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?


Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기




Community Treasure Hunt

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

Start Hunting!

Translated by