subscript indices must either be real positive integers or logicals

2 ビュー (過去 30 日間)
Antonina Evdokimova
Antonina Evdokimova 2012 年 11 月 18 日
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 件のコメント
Jan
Jan 2012 年 11 月 18 日
And which line causes the error?

サインインしてコメントする。

回答 (2 件)

Walter Roberson
Walter Roberson 2012 年 11 月 18 日
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));

Jan
Jan 2012 年 11 月 18 日
編集済み: Jan 2012 年 11 月 18 日
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;

カテゴリ

Help Center および File ExchangePHY Components についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by