How to make a code more interactive (command window)?
6 ビュー (過去 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!