Using numpad 8 2 6 4 as North South East West

2 views (last 30 days)
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 Comment
Samuel Angelo Regalado
Samuel Angelo Regalado on 11 Apr 2019
Edited: Samuel Angelo Regalado on 11 Apr 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

Sign in to comment.

Answers (1)

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

Categories

Find more on Price and Analyze Financial Instruments in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!