Using numpad 8 2 6 4 as North South East West

3 vues (au cours des 30 derniers jours)
Samuel Angelo Regalado
Samuel Angelo Regalado le 11 Avr 2019
Hi! I wanted to create a code where I can plot a variable using my numpad 8, 2, 6, 4, as North, South, East, West. The distance is also coded as an integer value. For example, the inputs 8 5 will mean the variable will move towards the North by a distance of 5 units. Assuming that the variable is initially at location (0,0)
  1 commentaire
Samuel Angelo Regalado
Samuel Angelo Regalado le 11 Avr 2019
Modifié(e) : Samuel Angelo Regalado le 11 Avr 2019
I have created a code but my code only seems to plot (x,y) variable :(( sorry I just started coding excuse my mistakes
choice = menu('Select one', '(1) Start', ' (2) Reset', '(3) Quit', '(0) Location');
if choice==1
clear;
clear all;
clc;
m=10;
for n = 1:m-1;
if n == 1;
xn = input('Input Direction: ');
fprintf('\n');
yn = input('Input Distance: ');
fprintf('\n');
x = [xn];
y = [yn];
fprintf('%d \n\n %f', x, y);
fprintf('\n\n');
plot(x,y,'-o','MarkerEdgeColor','red');
else
xn = input('Input Direction: ');
fprintf('\n');
yn = input('Input Distance: ');
fprintf('\n');
xadd = x(n-1);
yadd = y(n-1);
x = [x xn+xadd];
y = [y yn+yadd];
fprintf('\n\n');
xor = 0;
line([-max(x),max(x)],[xor,xor]);
hold on
plot([0 0],[-max(y) max(y)]);
hold on
plot(x,y,'-o','MarkerEdgeColor','red');
grid on;
ax = gca;
ax.XAxisLocation = 'origin';
ax.YAxisLocation = 'origin';
end
end
fprintf('here are your values of x and y\n')
x
fprintf('\n');
y
elseif choice==2
clear;
clear all;
clc;
m=5;
for n = 1:m-1;
if n == 1;
xn = input('Input Direction: ');
fprintf('\n');
yn = input('Input Distance: ');
fprintf('\n');
x = [xn];
y = [yn];
fprintf('%d \n\n %f', x, y);
fprintf('\n\n');
plot(x,y,'-o','MarkerEdgeColor','red');
else
xn = input('Input Direction: ');
fprintf('\n');
yn = input('Input Distance: ');
fprintf('\n');
xadd = x(n-1);
yadd = y(n-1);
x = [x xn+xadd];
y = [y yn+yadd];
fprintf('\n\n');
xor = 0;
line([-max(x),max(x)],[xor,xor]);
hold on
plot([0 0],[-max(y) max(y)]);
hold on
plot(x,y,'-o','MarkerEdgeColor','red');
grid on;
ax = gca;
ax.XAxisLocation = 'origin';
ax.YAxisLocation = 'origin';
end
end
fprintf('here are your values of x and y\n')
x
fprintf('\n');
y
elseif choice==3
disp = ('Normal program termination. Goodbye!')
else
plot(choice==1,'-o','MarkerEdgeColor','red');
end

Connectez-vous pour commenter.

Réponses (1)

Jos (10584)
Jos (10584) le 11 Avr 2019
Perphaps my getkey function may be of use to you:

Catégories

En savoir plus sur Price and Analyze Financial Instruments dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by