How to make a code more interactive (command window)?
6 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Chris
on 30 Oct 2021
Edited: Chris
on 30 Oct 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 Comments
More Answers (0)
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!