subscript indices must either be real positive integers or logicals
2 views (last 30 days)
Show older comments
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.
Answers (2)
Walter Roberson
on 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 Comments
Jan
on 18 Nov 2012
Edited: Jan
on 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 Comments
See Also
Categories
Find more on PHY Components in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!