Modifying a code (code by Mohammad alshikh khalil)

1 view (last 30 days)
Hi, I am trying to modify the following code to plot (lambdas, ans) where lambdas sis the wavelength range that I give as input and and is the results of the code. To run the code inputs need to be: coeffs [1.0792 6.0840 0.2822 1.900 27.62] and Lambdas range should be from 850 to 1500. when I use plot command, I get an error says the vector must be the same length. error: Error using plot Vectors must be the same lengths.
Error in sel (line 19)
plot (Lambdas, nn)
here is the code:
function nn = sel (coeffs, x )
%sel Calculate sellmier eqs
% n(l)^2 = A + c1*(x^2)/(x^2-L1^2) + c2*(x^2)/(x^2-L2^2) + ...,
% where x is the wavelength,
%A is the offset
% c1,c2,...,cN are the N Sellmeier coefficients
% L1,L2,...,LN are the n Sellmeier coefficients.
offset=coeffs(1);
L=x.^2;
Lambdas=coeffs(3:2:end).^2;%odd numbers
coeff=coeffs(2:2:end); % even numbers
ff=size(coeff);
ssum=0;
for mm=1:1:ff(2)
ssum=ssum+coeff(mm).*L./(L-Lambdas(mm));
end
nn=sqrt(offset+ssum);
end

Answers (1)

Nalini Vishnoi
Nalini Vishnoi on 6 May 2015
Hi,
Assuming that you are using the following code:
>> coeffs = [1.0792 6.0840 0.2822 1.900 27.62];
>> x = 850:1500;
>> sel(coeffs, x);
and using a
plot(Lambdas, nn);
command inside the 'sel' function, I see that size of Lambdas is 1x2 and size of nn is 1x651. plot command needs the two vectors which are to be plotted to be of the same size. Since they are of different size in this case, hence the error is generated. Did you want to pass 'x' as x = [850 1500]; instead?
-Nalini

Community Treasure Hunt

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

Start Hunting!