Need help with App designer

Currently I had a project that ive been working on for a while, I had a bunch of issues at the start that i was able to over come.
Basically the project is about making an app that uses projectile motion, so a point X is marked once the user pressed new and you input velocity and angle, and see how close the user is to the point and give them a score based on their first 5 tries
My issues right now are the following:
I am unable to have the X stay on the UIAxis when the plot of the user is inputted.
The plot of the user isnt working for some reason I am unsure of why.
And finally I am supposed to make a barrier so once the useres plot passes the X axis it stops.
I have looked around for examples but i am unable to find examples that will help me overcome my issues.
Here is my code to date:
Ive been testing out multiple ways to get it to work with no avail unfortunatly which has led me to resorting for help
% Button pushed function: NewButton
function NewButtonPushed(app, event)
x1 = 0:10;
y1 = 0:100;
x2 = randi(length(x1));
y2 = randi(length(y1));
plot(app.UIAxes,x2,y2,'x','Color','red','MarkerSize',10);
axis(app.UIAxes,[0,10,0,100]);
app.pushed = app.pushed + 1;
if app.pushed == 1
clear,clc
app.pushed = 0;
end
end
% Button pushed function: GoButton
function GoButtonPushed(app, event)
%Defining Variables
theta = app.AngleEditField.Value;
v = app.VelocityEditField.Value;
y0 = 1.5;
x0 = 0;
thetarad = theta * (pi./180);
%Defining different velocities
%vx = v*cosd(theta);
%vy = v*sind(theta);
%Quadtaric Formula for time
%a = (1/2)*app.g;
%b = vy;
%c = y0;
%tEnd = roots([a,b,c]);
%tEnd = max(tEnd);
%Calulation of X components
xs = (v^2)./app.g*sin(2*thetarad);
xt = xs ./ 100;
%Defining the coordinates:
x = x0:xs:xt;
y = (x*tan(thetarad) - app.g/(2*(v^2)*cos(thetarad).^2)*x.^2)+y0;
for i = 1:length(x)
plot(app.UIAxis, x(i), y(i), '.');
hold on;
pause(0.0001);
end
end

Respuestas (1)

Adam Danz
Adam Danz el 24 de Abr. de 2020

1 voto

The hold command needs to specify the axes and it needs to be called prior to adding objects to the plot.
hold(app.UIAxes, 'on')
To limit the x values to the maximum axis limit,
min(x(i), max(xlim(app.UIAxes)))

9 comentarios

Amr Assar
Amr Assar el 24 de Abr. de 2020
I have fixed a few more erros and added that however i am not getting this error:
Unrecognized method, property, or field 'UIAxis' for class 'app1'.
Adam Danz
Adam Danz el 24 de Abr. de 2020
Editada: Adam Danz el 24 de Abr. de 2020
"app.UIAxes" was pulled from the code in your question.
That should be replaced with whatever your uiaxis handle is.
Amr Assar
Amr Assar el 24 de Abr. de 2020
it is UIAxes so i dunno why its not working
Amr Assar
Amr Assar el 24 de Abr. de 2020
Oh my i wrote Axis my bad lmao
Adam Danz
Adam Danz el 24 de Abr. de 2020
Editada: Adam Danz el 24 de Abr. de 2020
Sounds like you worked it out!
If you have any further problems with this, feel free to continue the discussion here.
Amr Assar
Amr Assar el 24 de Abr. de 2020
Well now the plot apparently only plots one dot which is weird for some reason, Im curious if there is anything wrong with my code which is why it isnt plotting properly/ linear lines instead just one dots
Adam Danz
Adam Danz el 24 de Abr. de 2020
If you share your updated code and explain the order that callback functions are called (if >1 callback), I could help.
Amr Assar
Amr Assar el 24 de Abr. de 2020
% This is all the code till now
properties (Access = private)
pushed = 0;
g = 9.81; % Description
end
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: NewButton
function NewButtonPushed(app, event)
x1 = 0:10;
y1 = 0:100;
x2 = randi(length(x1));
y2 = randi(length(y1));
plot(app.UIAxes,x2,y2,'x','Color','red','MarkerSize',10);
axis(app.UIAxes,[0,10,0,100]);
app.pushed = app.pushed + 1;
if app.pushed == 1
clear
clc
app.pushed = 0;
end
end
% Button pushed function: GoButton
function GoButtonPushed(app, event)
%Defining Variables
theta = app.AngleEditField.Value;
v = app.VelocityEditField.Value;
y0 = 1.5;
x0 = 0;
thetarad = theta * (pi./180);
%Defining different velocities
vx = v*cosd(theta);
vy = v*sind(theta);
%Quadtaric Formula for time
%Calulation of X components
xs = (v^2)./app.g*sin(2*thetarad);
xt = xs/ 100;
%Defining the coordinates:
x = x0:xs:xt;
y = (x*tan(thetarad) - app.g/(2*(v^2)*cos(thetarad).^2)*x.^2)+y0;
for i = 1:length(x)
hold(app.UIAxes, 'on')
plot(app.UIAxes, x(i), y(i), '.');
hold(app.UIAxes, 'on')
pause(0.0001);
end
Adam Danz
Adam Danz el 24 de Abr. de 2020
Editada: Adam Danz el 28 de Abr. de 2020
Which button is pressed first? You might need to "hold on" in the NewButtonPushed function, too.
These two lines can be removed.
if app.pushed == 1
clear % <-- why clear variables?
clc % <-- why the need to clear the command window?
app.pushed = 0;
end
hold on only needs executed once. There's no harm in executing it more than once but there's also no need.
for i = 1:length(x)
hold(app.UIAxes, 'on') %<-- move this outside of the loop or somewhere else.
plot(app.UIAxes, x(i), y(i), '.');
hold(app.UIAxes, 'on') % <-- remove this
pause(0.0001);
end
Lastly, check that your x and y values contain more than 1 coordinate.
If that doesn't solve the problem, please share your updated code.

Iniciar sesión para comentar.

Categorías

Más información sobre Develop Apps Using App Designer en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 24 de Abr. de 2020

Editada:

el 28 de Abr. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by