Why do I get the error?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
This is my code
t=0:.1:5;
u(1:25)=.1;
u(26:51)=-.1;
plot(t,u);
[to,yo]=sim('hw3',5,[],[t',u']);
%Finding u_final and cost
l_b=ones(51,1)*(-50);
u_b=ones(51,1)*50;
options=optimset('Display','iter','PlotFcns','optimplotx');
[u_final,cost]=fmincon('find_cost',u,[],[],[],[],l_b,u_b,'find_constraint',options);
[t_f,x_f,y_f]=sim('hw3',5,[],[t' u_final']);
figure(3);
subplot(t_f,y_f(:,1));
grid;
xlabel('Time');
ylabel('Position');
figure(4);
subplot(t_f,y_f(:,2));
grid;
xlabel('Time');
ylabel('Velocity');
figure(5);
subplot(t_f,y_f(:,3));
grid;
xlabel('Time');
ylabel('Acceleration');
figure(6);
subplot(t_f,y_f(:,4));
grid;
xlabel('Time');
ylabel('Jerk');
figure(7);
subplot(t_f,y_f(:,5));
grid;
xlabel('Time');
ylabel('Jounce');
Every time i run the code it says Vectors must be of same length.
u and t should be of same size. Please help
6 commentaires
Réponses (1)
KSSV
le 23 Fév 2018
Use this:
t=0:.1:5;
u = zeros(size(t)) ;
u(1:round(length(t)/2))=.1;
u(round(length(t)/2)+1:end)=-.1;
plot(t,u);
0 commentaires
Voir également
Catégories
En savoir plus sur Deep Learning Toolbox dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!