필터 지우기
필터 지우기

How can i solve 'vector's length is different'

조회 수: 1 (최근 30일)
주선 문
주선 문 2022년 8월 25일
답변: Anuneet 2022년 9월 7일
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

답변 (1개)

Anuneet
Anuneet 2022년 9월 7일
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;

카테고리

Help CenterFile Exchange에서 함수 기본 사항에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!