Weighting based on Eigenvector method
7 views (last 30 days)
Show older comments
i am constructing a simple eigenvector method for a 6 rows X 10 columns matrix.This is main part of the code, the values in PM=[] have been omitted due to the large amount of input numbers
PM=[]
Wt(:,1)=[1;0;0;0;0;0;0;0;0;0];
[len,width]=size(PM);
delta(:,1)=[1 1 1 1 1 1 1 1 1 1]';
trial=18;
for t=2:trial
Wt1(:,t)=PM*Wt(:,t-1);
max_eig=sum(Wt1(:,t));
Wtnorm1(:,t)=Wt1(:,t)./max_eig;
delta(:,t)=abs(Wt(:,t-1)-Wtnorm1(:,t));
if delta(:,t-1)>=1e-6
Wt(:,t)=Wtnorm1(:,t);
else
CI=(max_eig-width)/(width-1);
weight=Wtnorm1;
break
end
end
final_weight=weight(:,length(weight));
unfortunately i cant seem to diagnose this error:
??? Attempted to access weight(:,10); index out of bounds because size(weight)=[10,4].
Error in ==> eigenvector at 31 final_weight=weight(:,length(weight));
i am pretty new to matlab so i am not sure how to read these error messages.thanks alot!
1 Comment
the cyclist
on 21 Mar 2012
Are you able to give a toy example of PM that will exhibit the error behavior, without all the real values? I tried PM = rand(6,10), but that gives an error earlier in the code.
Answers (2)
the cyclist
on 21 Mar 2012
It is hard to dig deeper without being able to run your code. However, the specific error is that length(weight) is equal to 10 (because length() returns the longer dimension of a 2-d array). But since weight is 10x4, you are trying to access the 10th column of an array that only has 4 columns. Hence, the error.
0 Comments
Richard
on 21 Mar 2012
1 Comment
the cyclist
on 21 Mar 2012
I won't say that I deeply understand code. But, working backward, what is happening is the following:
(1) The 2nd dimension of "weight" is not as long as length(weight), so you are trying to index into an element that does not exist. In other words, the variable "weight" doesn't have enough columns.
(2) The reason that "weight" doesn't have enough columns is that you break out of the loop before you have created the columns you need.
(3) You break out of the loop based on the value of delta.
So, I am not exactly sure what is going wrong, but something in that chain is not working in the same way as your smaller 3x3 example.
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!