Index exceeds matrix dimensions when I tried to execute this code.

1 回表示 (過去 30 日間)
Saint Dee
Saint Dee 2018 年 4 月 9 日
コメント済み: Walter Roberson 2018 年 4 月 9 日
for i = 1:I %%I = 10
for k = 1:K %%K = 100
rate(i,k,:) = W*log2(1+sinr); %%W = 20*10^6
energy_eff(i,k) = (b(i,k)*rate(i,k)/P_ci); %%b=linspace(0,1,10)
  2 件のコメント
KSSV
KSSV 2018 年 4 月 9 日
Which line it showed error? YOu need to check the dimensions of b and rate....are they of size 10*100?
Saint Dee
Saint Dee 2018 年 4 月 9 日
On the fourth line : energy_eff(i,k)

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

採用された回答

Walter Roberson
Walter Roberson 2018 年 4 月 9 日
b=linspace(0,1,10)
so it is a row vector. But in the line
energy_eff(i,k) = (b(i,k)*rate(i,k)/P_ci); %%b=linspace(0,1,10)
you are trying to index b(i,k) which is going to fail as soon as i becomes 2.
  2 件のコメント
Saint Dee
Saint Dee 2018 年 4 月 9 日
Thank you Walter. How do I correct that please? There are no strict rules for the values.I really want to plot sinr against energy_eff and rate. Thanks.
Walter Roberson
Walter Roberson 2018 年 4 月 9 日
I do not know what your equations are. For this purpose, element-by-element multiplication is important compared to matrix multiplication.
Also, I just noticed that you assign to rate(i,k,:) but on that 4th line you access rate(i,k) with no third dimension.
My guess is you need
b'*squeeze(rate(i,k,:))
or something like that. Or
dot(b, squeeze(rate(i,k,:)) )

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by