problem using for loop

3 ビュー (過去 30 日間)
james morley
james morley 2020 年 4 月 27 日
回答済み: Sriram Tadavarty 2020 年 4 月 27 日
I'm having issues with the for loop below. It is meant to cycle through 0 to 12 snr values and then at the end show a final BER value for each of the iterations of snr. Currently the final BER is just showing what happens at the end of the loop when the snr=12. How can i create an array to show every BER value from snr=0:12?
  3 件のコメント
james morley
james morley 2020 年 4 月 27 日
Thats worked, thank you so much!
Sriram Tadavarty
Sriram Tadavarty 2020 年 4 月 27 日
Glad it helped.
I will place the same in answer.

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

回答 (1 件)

Sriram Tadavarty
Sriram Tadavarty 2020 年 4 月 27 日
Hi James,
The variable is updated with the latest value in the for loop, leading to have only single value at the end of the for loop.
Make it an array by indexing the value of each snr point, to have the array of values at the end of loop.
Since, sn starts from 0, and is contiguous, you can use the following:
finalBER(sn+1) = numerrs/N;
If sn is not from 0 or if the SNR values are not steps of 1, try the following:
count = 1;
...
for sn = SNR
...
finalBER(count) = numerrs/N;
count = count+1;
end
You can work of with first case, as the SNR is from 0 and is contiguous.
Hope this helps.
Regards,
Sriram

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by