Plot specific UIAxes command in a function
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (2)
Katie
am 23 Okt. 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!
Siehe auch
Kategorien
Mehr zu Graphics Object Programming finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!