MATLAB attempted to access x(1,3), index out of bounds because numel(x)=1.
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
HOW IT HAPPEND= = AND I WANNA KNOW HOW TO CORRECT.DO ME A FAVOR I WILL APPRECIATE FORERVER,BECAUSE THE CODE CONNECTS WITH ONE IMPORTANT TEST.HELP!!!
7 Comments
Matt Kindig
on 30 Apr 2013
Please format your code by highlighting it, and then clicking the '{} Code' button above. We cannot read/run your code as it is written.
Matt Kindig
on 30 Apr 2013
x=0 creates a variable that is 1x1 (1 row, 1 column) in size. Thus, accessing x(i,3) throws an error, since x does not have 3 columns.
Matt Kindig
on 30 Apr 2013
By the way, exactly what is your code supposed to do? By setting elements of D to x (which == 0), you are just setting D = 0. However, you already have a matrix of zeros with the D=zeros(154) line. The D1=D+D' line then gives D1 as a matrix of zeros as well.
What you you expect D1 to look like?
sally
on 30 Apr 2013
Azzi Abdelmalek
on 30 Apr 2013
Edited: Azzi Abdelmalek
on 30 Apr 2013
I've edited your code twice, and you are making it each time unreadable
sally
on 30 Apr 2013
Walter Roberson
on 1 May 2013
Duplicates by later http://www.mathworks.co.uk/matlabcentral/answers/74170-how-to-correct-attempted-to-access-x-1-3-index-out-of-bounds-because-numel-x-1 which also has discussion. Discussion should continue here instead of there.
Answers (1)
Azzi Abdelmalek
on 30 Apr 2013
Because you set x to 0, which means its length is 1, you can not use
x(i,1)
with i>1
Categories
Find more on Direction of Arrival Estimation 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!