what is wrong with my function code

2 visualizzazioni (ultimi 30 giorni)
Mohammed Alqanber
Mohammed Alqanber il 6 Nov 2015
Modificato: Stephen23 il 7 Nov 2015
clear all;
close all;
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=1000000;
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
end
  1 Commento
Stephen23
Stephen23 il 7 Nov 2015
Modificato: Stephen23 il 7 Nov 2015
The Problem is called cargo-cult programming: beginners use clear all and close all, without knowing why they are doing this.
The Solution is to stop using clear all and close all at the beginning of every function, without knowing what they are actually useful for, and when they should be used.

Accedi per commentare.

Risposte (1)

Walter Roberson
Walter Roberson il 7 Nov 2015
You need to delete the lines
clear all;
close all;

Categorie

Scopri di più su Files and Folders in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by