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 中查找有关 Numerical Integration and Differential Equations 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by