Index exceeds matrix dimensions

1 回表示 (過去 30 日間)
Joseph
Joseph 2015 年 7 月 14 日
回答済み: Walter Roberson 2015 年 7 月 15 日
Hi
i'm trying to run the program below, so i have a 5*5 matrix which is y and and i'm trying to calculate E=sigma_{i,k}y(i,k)*((v+0.5)^(i-1))*((j(j+1))^(k-1)) summing over i=1:5 & k=1:5 for specific v&j and keep doing this summation for different v=1:10 and j=1:150, there for i must have a E matrix with dimension 10*150, but with the code i mentioned below, i get an error saying "Index exceeds matrix dimensions"
i attached the matlab file.
thank you
clear
clear all;
y=[0 0.243930066 -2.50171E-07 -4.652E-14 9.585E-19; 481.774655 -0.001611082 4.4226E-10 0 0;
-2.1018112 4.69192E-06 7.026E-12 0 0; 0.0066384 -5.282E-09 0 0 0; -0.000020255 0 0 0 0]
n=nan(10,150);
E=0
for v=1:10
for j=1:150;
for i=1:5;
for k=1:5;
E(v,j,i,k)=E+y(i,k)*((v+0.5)^(i-1))*((j(j+1))^(k-1));
n=E;
end
end
end
end

採用された回答

Walter Roberson
Walter Roberson 2015 年 7 月 15 日
Your code has
j(j+1)
which says to index the variable "j" at location "j+1". You probably want
j*(j+1)

その他の回答 (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