Index exceeds matrix dimensions

1 Ansicht (letzte 30 Tage)
Joseph
Joseph am 14 Jul. 2015
Beantwortet: Walter Roberson am 15 Jul. 2015
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

Akzeptierte Antwort

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

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by