フィルターのクリア

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 Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by