Using numpad 8 2 6 4 as North South East West

3 visualizzazioni (ultimi 30 giorni)
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 Commento
Samuel Angelo Regalado
Samuel Angelo Regalado il 11 Apr 2019
Modificato: Samuel Angelo Regalado il 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

Accedi per commentare.

Risposte (1)

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

Categorie

Scopri di più su Price and Analyze Financial Instruments in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by