Understanding the following step in MATLAB

6 ビュー (過去 30 日間)
charu shree
charu shree 2023 年 7 月 5 日
コメント済み: charu shree 2023 年 7 月 5 日
Hello all, I came across the following code on MATLAB but not getting its last step:
symbols = randi([0 3], 1, 256);
constellation = [1+1i, -1+1i, -1-1i, 1-1i];
signal = constellation(symbols + 1); % Last step
My query is why " symbols +1 " is written in last step and why not only " symbols".
Any help in this regard will be highly appreciated.

採用された回答

the cyclist
the cyclist 2023 年 7 月 5 日
The line
symbols = randi([0 3], 1, 256)
generates random values from the values [0 1 2 3]. Those zero values are not a valid index int the constellation vector, in other words
constellation(0)
would throw an error, because there is no "zeroth element". So, I presume this person adds the 1 to get valid indexing.
They could also have done
symbols = randi([1 4], 1, 256); % Note that I changed the random numbers generated
constellation = [1+1i, -1+1i, -1-1i, 1-1i];
signal = constellation(symbols); % Note that I took away the +1
I'm not sure why they did not code it this way, but maybe the zeros are need later.
  1 件のコメント
charu shree
charu shree 2023 年 7 月 5 日
@the cyclist, Thanks a lot sir for such a wonderful response...

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

その他の回答 (1 件)

Paul
Paul 2023 年 7 月 5 日
編集済み: Paul 2023 年 7 月 5 日
The elements in symbols range from 0 - 3, but Matlab uses 1-based indexing, i.e. the indices int0 constellation can only be 1-4.
  1 件のコメント
charu shree
charu shree 2023 年 7 月 5 日
@Paul, Thank u so much sir for the reply...

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

カテゴリ

Help Center および File ExchangeTime-Frequency Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by