How to make a code more interactive (command window)?
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Chris
2021-10-30
编辑:Chris
2021-10-30
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!