필터 지우기
필터 지우기

Modifying a code (code by Mohammad alshikh khalil)

조회 수: 4 (최근 30일)
Jackol Jackil
Jackol Jackil 2015년 5월 2일
답변: Nalini Vishnoi 2015년 5월 6일
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
  댓글 수: 2
Jackol Jackil
Jackol Jackil 2015년 5월 2일
I would be very thankful if someone help me
Star Strider
Star Strider 2015년 5월 2일
There is no plot call in the code you posted.

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

답변 (1개)

Nalini Vishnoi
Nalini Vishnoi 2015년 5월 6일
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

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by