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.

1 visualizzazione (ultimi 30 giorni)
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)

Risposta accettata

Mischa Kim
Mischa Kim il 23 Giu 2014
Modificato: Mischa Kim il 23 Giu 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 Commenti
Mischa Kim
Mischa Kim il 23 Giu 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
Jose Cruz il 21 Set 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

Accedi per commentare.

Più risposte (0)

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by