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
回答(1 个)
Adam Danz
2020-4-24
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 个评论
Amr Assar
2020-4-24
Amr Assar
2020-4-24
Amr Assar
2020-4-24
Amr Assar
2020-4-24
Adam Danz
2020-4-24
If you share your updated code and explain the order that callback functions are called (if >1 callback), I could help.
Amr Assar
2020-4-24
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.
类别
在 帮助中心 和 File Exchange 中查找有关 Develop Apps Using App Designer 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!