cannot find the error in my code

4 ビュー (過去 30 日間)
Mohammed Alqanber
Mohammed Alqanber 2015 年 11 月 10 日
編集済み: Stephen23 2015 年 11 月 11 日
This is my code
function out=random_rayleigh(x,y)
msg = nargchk(0,2,nargin);
error(msg);
if nargin <1
y=1;
x=1;
elseif nargin <2
y=x;
end
array1=randn(x,y);
array2=randn(x,y);
out=sqrt(array1.^2+array2.^2);
no_of_samples=500;
mean_noise_level=10;
Detection_threshold_dB=[5.,6.,7.,8.,9.,10.,11.,12.,13.];
threshold_in_v=mean_noise_level.*10.0.^(Detection_threshold_dB/20.);
tota_samples=mean_noise_level/1.25*random_rayleigh(1,no_of_samples);
for jj=1:length(threshold_in_v)
total(jj)=sum(total_samples>threshold_in_v(jj));
end
fprintf('the constant false alarm rate for the threshold level is:');
for jj = 1:length(threshold_in_v)
fprintf('threshold(volts)=%5.1f dB Pfa=%14.5e', Detection_threshold_dB(jj),total(jj)/no_of_samples);
end
This is the error message I got
Maximum recursion limit of 500 reached. Use set(0,'RecursionLimit',N) to change the limit. Be aware that exceeding your available stack space can crash MATLAB and/or your computer.
Error in random_rayleigh

回答 (3 件)

Torsten
Torsten 2015 年 11 月 10 日
It seems you call random_rayleigh within random_rayleigh more than 500 times ...
Best wishes
Torsten.

Stephen23
Stephen23 2015 年 11 月 10 日
編集済み: Stephen23 2015 年 11 月 11 日
Your function random_rayleigh calls itself on this line:
tota_samples=mean_noise_level/1.25*random_rayleigh(1,no_of_samples);
But there is not count-down or count-up to some limit, so there is no limit to how many times this function will call itself.
But considering that the output value tota_samples is not used, why are you calling this function inside itself anyway? If its output is not used, then why call it?

Thorsten
Thorsten 2015 年 11 月 10 日
Basically your function is
function out=random_rayleigh(x,y)
% some code
tota_samples=mean_noise_level/1.25*random_rayleigh(1,no_of_samples);
%more code
So if you call random_rayleigh, you end up in an endless recursion of calling random_rayleigh.

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by