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 views (last 30 days)
Show older comments
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)
0 Comments
Accepted Answer
Mischa Kim
on 23 Jun 2014
Edited: Mischa Kim
on 23 Jun 2014
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 Comments
Mischa Kim
on 23 Jun 2014
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
on 21 Sep 2019
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
More Answers (0)
See Also
Categories
Find more on Assembly in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!