subscript indices must either be real positive integers or logicals
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello,
I have a following function
% BER.m
function probability = BER(Sin, Sout, MTrans)
rate = 0;
for k = 1: MTrans
if Sin(k) == Sout(k)
rate = rate+1;
end
end
probability = rate/MTrans;
And I use this function in the Main.m file
BER = BER(DataGenOut, DataRx_Out , MTrans);
The rest of the code in Main.m is compiled correctly. Thank you in advance for your help.
1 Kommentar
Antworten (2)
Walter Roberson
am 18 Nov. 2012
Do not use a variable that is named the same thing as your function. After the first execution of such a line, BER would no longer refer to the function and would refer to the variable you had created.
Note: you can simplify your function to the line
probability = mean(Sin(1:MTrans) == Sout(1:MTrans));
0 Kommentare
Jan
am 18 Nov. 2012
Bearbeitet: Jan
am 18 Nov. 2012
In the line:
BER = BER(DataGenOut, DataRx_Out , MTrans);
the function "BER" is overwritten by the local variable with the same name. If you call "BER" afterwards again, the following arguments are treated as indices.
Btw. your function can be simplified:
function probability = BER(Sin, Sout, MTrans)
probability = sum(Sin(1:MTrans) == Sout(1:MTrans)) / MTrans;
0 Kommentare
Siehe auch
Kategorien
Mehr zu PHY Components finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!