subscript indices must either be real positive integers or logicals
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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.
Réponses (2)
Walter Roberson
le 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 commentaires
Jan
le 18 Nov 2012
Modifié(e) : Jan
le 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 commentaires
Voir également
Catégories
En savoir plus sur PHY Components dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!