필터 지우기
필터 지우기

I am getting this error- "Vectors must be the same lengths.". Also please explain why its showing this error as I am plotting a funtion with 'x' as variable with defined vector.

조회 수: 2 (최근 30일)
clear all
rr=0.99997622; % reflectivity of the cavity
r=sqrt(rr);
finesse=pi.*sqrt(rr)./(1-rr); % finesse of the cavity
fsr=10^9;
x=-9e4:10:9e4; % frequnecy detuning
z=x./fsr;
FWHM=fsr./finesse;
mod=40e6; % modulation frequency to the laser
m=mod./fsr;
g=r.*(exp(((x./fsr).*(2.*pi)).*1i)-1)./(1-(r.^2).*exp(((x./fsr).*(2.*pi)).*1i));
abg=abs(g);
sg=power(abg,2);
dfg=diff(sg);
y=m.*dfg;
plot(x,y)

채택된 답변

Mischa Kim
Mischa Kim 2014년 6월 23일
편집: Mischa Kim 2014년 6월 23일
Jayash, with the diff command you compute the difference between elements in a vector thereby reducing the number of elements by one. Use instead
plot(x(2:end),y)
  댓글 수: 3
Mischa Kim
Mischa Kim 2014년 6월 23일
a = [1 2 10];
b = diff(a)
b =
1 8
As explained above, diff computes the differene btw. vector elements. Therefore, b (in this case) only has two elements, not three.
Jose Cruz
Jose Cruz 2019년 9월 21일
Mischa,
What if my problem is similar but I need to multiply the Diff () = dVdt [1369 x 1] with V [1370 x 1] equation. How can I add to the lenght of dVdt?
Matrix dimensions must agree.
Error in homework_1_P2 (line 40)
Inertia = (1.1*Mv*(dVdt).*V)./1000; % kW
load CYC_FUDS.mat
t = cyc_mph(:,1); % Time [s]
Vmph = cyc_mph(:,2); % Velocity [mph]
V = Vmph.*(1609/3600); % Velocity [m/s]
dVdt = (diff(V)./diff(t)); % Accel. m/s^2
Inertia = (1.1*Mv*(dVdt).*V)./1000; % kW

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Assembly에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by