- You would use components of x that would be zeros to index D.
- Even if it were working, the FOR loop would redefine D as zero, which is what it is anyway after you initialize it using D=zeros(154).
HOW TO CORRECT attempted to access x(1,3), index out of bounds because numel(x)=1.
2 views (last 30 days)
Show older comments
clc
clear all
x=0;
D=zeros(154);
for i=1:248
D(x(i,1),x(i,2))=x(i,3);
end
D1=D+D';
for i=1:154
for j=1:154
if D1(i,j)==0
D1(i,j)=inf;
end
end
end
for i=1:154
for j=1:154
if i==j
D1(i,j)=0;
end
end
end
I JUST WANNA KNOW HOW TO CORRECT.... I FEEL I WILL BE CRAYZY(wuwuwu)
8 Comments
Cedric
on 1 May 2013
Edited: Cedric
on 1 May 2013
As I said above: you should first switch to lower case when you write on the forum.
Then, how much time do you have for building this adjacency matrix? Is it for a homework, a longer term project, a Master/Ph.D. thesis?
EDIT: I'm off for the night; anyway, you want x to be a 248x3 array before the first FOR loop starts, not 0 as you defined it. Moreover, the first two columns of x must be positive integers below or equal to 154 (ID of vertices I guess).
Then, the rest should work, but the two nested FOR loop statements can be done way more efficiently (in one line each). We can talk about this, but you'll have to answer my question about the time frame and the nature of this work first.
Walter Roberson
on 1 May 2013
Duplicates earlier http://www.mathworks.co.uk/matlabcentral/answers/74151-matlab-attempted-to-access-x-1-3-index-out-of-bounds-because-numel-x-1 which also has discussion. Further discussion should go there.
Answers (0)
See Also
Categories
Find more on Directed Graphs 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!