Index exceeds matrix dimensions.

if(X(n,5)==X(i(c),5));

댓글 수: 12

KSSV
KSSV 2018년 6월 20일
편집: Birdman 2018년 6월 20일
You need to show full code.....this error occurs when you try to extract more number of elements then present in the array. Check your dimensions.
div
div 2018년 6월 20일
if(X(n,5)==X(i(c),5)); sir can u tell me how to write this code in another way...i m new in matlab
KSSV
KSSV 2018년 6월 20일
We cannot help unless the purpose and dimensions of the variables needed. Copy the complete code here.
div
div 2018년 6월 20일
편집: div 2018년 6월 20일
for f=1:m
for i=1:m
for j=1:4
di=abs(X(f,j)-X(i,j));
Z(i)=di;
end
[B,I]=sort(Z);
for c=1:20
if(X(f,5)==X(I(c),5))
k=0
end
end
end
end
Torsten
Torsten 2018년 6월 20일
Variable "n" is undefined.
div
div 2018년 6월 20일
sorry in place of n there is f
KSSV
KSSV 2018년 6월 20일
편집: KSSV 2018년 6월 20일
What is X?
Check this line: X(i(c),5)..your i is a loop variable, it is a scalar....you are trying to access i as a vector in i(c). You need to rethink on this.
div
div 2018년 6월 20일
X is a file where data is stored
div
div 2018년 6월 20일
how can i solve this sir ...i tried bt no results.
div
div 2018년 6월 20일
편집: Torsten 2018년 6월 20일
for f=1:m
for i=1:m
for j=1:4
di=abs(X(f,j)-X(i,j));
Z(i)=di;
end
[B,I]=sort(Z);
for c=1:20
if(X(f,5)==X(I(c),5))
k=0
end
end
end
end
What does "X is a file" mean? The name of the file?
In the body of the question, there is a lower-case "i", but in the code in the comment an upper-case "I".
Does the code in the comment solve your question?
In
for j=1:4
di=abs(X(f,j)-X(i,j));
Z(i)=di;
end
You overwrite the value of Z(i) 3 times. Afterwards Z(i) contains only the value for j=4.

답변 (0개)

이 질문은 마감되었습니다.

태그

질문:

div
2018년 6월 20일

마감:

2021년 8월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by