How to make a code more interactive (command window)?
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Gargolla9
am 30 Okt. 2021
Bearbeitet: Gargolla9
am 1 Nov. 2021
Hi everyone! I would like to make this code more interactive. At the end of this code I have three functions that simulate three different types of dynamics. Once I have selected one of them, I have to pass the selected function to the ode45 to obtain my results. I would like the user to interactively choose (using the command window) which type of function to pass to the ode45.
clc; clear all; close all;
B = load('PosRel.txt');
time = B(:,1);
num_times = size(time,1);
%initial Euler Angles
alpha0 = convang(0,'deg','rad');
beta0 = convang(0,'deg','rad');
gamma0 = convang(0,'deg','rad');
vAlphaBetaGamma0 = [alpha0, beta0, gamma0];
[vTime, vAlphaBetaGamma] = ode45(@function,time,vAlphaBetaGamma0);
alpha = vAlphaBetaGamma(:,1);
beta = vAlphaBetaGamma(:,2);
gamma = vAlphaBetaGamma(:,3);
alpha = convang(alpha,'rad','deg');
beta = convang(beta,'rad','deg');
gamma = convang (gamma,'rad','deg');
figure
plot(vTime, alpha, 'k', vTime, beta, 'r', vTime, gamma, 'b');
legend('alpha','beta','gamma');
xlabel('Tempi (secondi)');
ylabel('Gradi');
0 Kommentare
Akzeptierte Antwort
Chris
am 30 Okt. 2021
Bearbeitet: Chris
am 30 Okt. 2021
disp("1 - spin")
disp("2 - tumbling")
disp("3 - three axis stab")
ftype = input("Select function type by number: ");
switch ftype
case 1
fun = @spin;
case 2
fun = @tumbling;
case 3
fun = @threeaxisstab;
otherwise
error('Type not recognized')
end
[vTime, vAlphaBetaGamma] = ode45(fun,time,vAlphaBetaGamma0);
You could also wrap this in a while loop and change the error to a warning or simply disp('Type not recognized') to continue prompting the user if the input is bad.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Ordinary Differential Equations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!