How to make a code more interactive (command window)?
조회 수: 1 (최근 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!