How can i solve 'vector's length is different'
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
clc, close all;
r=0.012*24;Nmax=1.15*10^7;
dt=100;
t=0:dt:100; n=100;
fdot=3*10^(-10); vmed= 1/(10*(1-0.002)); fent=fdot*vmed;
Nexi(1)=1.66*10^6; Npen=8.9;
Nent(1)=fent*Nexi(1);
Nddotout = zeros(n+1, 1);
Nddotent = zeros(n+1, 1);
for i=2:n
t(i+1)=t(i)+dt;
H(i)=(1/dt)*((1/dt)-2*(r-fent)+(4*r/Nmax)*(Nexi(i-1)))+(r-fent)^2;
Nexi(i)=((-1/dt)+r-fent+(H(i))^2)/(2*r/Nmax);
Nent(i)=fdot*vmed*Nexi(i);
Nout(i)=Npen+Nent(i);
fprintf('%.4f %.4f\n', t(i), Nout(i));
plot(t,Nout,t,Nent);
grid on;
end
다음 사용 중 오류가 발생함: plot
벡터들의 길이는 같아야 합니다.
오류 발생: matlab (line 15)
plot(t,Nout,t,Nent);
how can i fix it
0 commentaires
Réponses (1)
Anuneet
le 7 Sep 2022
Hi,
In the code snippet provided, you have initialised t as a vector of size 1 x 2 and Nexi and Nent as vectors of size 1 x 1.
During each iteration of the for loop, the sizes of t, Nexi, Nent and Nout are incremented by 1. However, the size of t is always 1 more than the others as its initial size was more. This is causing an error as the plot function expects vectors of the same size as input.
Based on my understanding of the provided code snippet, I suspect line 11 is supposed to be as follows :-
t(i) = t(i - 1) + dt;
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!