Index exceeds matrix dimensions

1 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by