how to make a comparison in a for loop. Problem on indexes

조회 수: 3 (최근 30일)
mazari ahmed
mazari ahmed 2015년 3월 14일
답변: mazari ahmed 2015년 4월 9일
At the end of the for loop l want to compare the values of I(i) and I(j) look at the second for loop. here is the returned error :
??? Attempted to access I(2); index out of bounds because numel(I)=1.
Error in ==> eliminationphase at 143
if (I(i)==I(j)&&(j < i))
Look at the code below:
alpha= 10;
I=1;
for i=1:N
if (~ismember(num2str(i), num2str(F)))
while (C(i) < alpha)
for j=1:N
if ((i~=j) && (ismember(j, neighbour_n{i})))
C(i)=C(i)+C(j);
display(['la somme des cardinaux de ', num2str(i), ' is ', num2str(C(i))]);
I=I+1;
display(['The number of iteration of ', num2str(i), ' is ', num2str(I)]);
end
end
end
if (~ismember(num2str(i), num2str(F)))
display(['the value of the node: ', num2str(i), ' at the end of while is ; ', num2str(C(i))]);
end
end
end
% how to compare betwwen I(i) and l(j)?
% l need to retreive the all the values of I and compare between them and between thein indices
for i=1:N
for j=1:N
if (((~ismember(num2str(i), num2str(F)))&&(~ismember(num2str(i), num2str(F))))&&(i~=j))
if (I(i)==I(j)&&(j < i))
display(i);
end
if (I(i) >I(j))
display(i);
end
end
end
end
  댓글 수: 4
Geoff Hayes
Geoff Hayes 2015년 3월 14일
Why do you have the following condition in the inner for loop of your second loop block
if (((~ismember(num2str(i), num2str(F)))&&(~ismember(num2str(i), num2str(F))))&&(i~=j))
What is the intent behind this code?
mazari ahmed
mazari ahmed 2015년 4월 9일
Finally you are right Geoff, it's working

댓글을 달려면 로그인하십시오.

답변 (1개)

mazari ahmed
mazari ahmed 2015년 4월 9일
Finally you are right Geoff, it's working

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by