Hello, Im trying to modify a matrix with if statements, not sure if Im approaching it the correct way. Here's the problem, I have a variable nn=6 in this case, and two matrices of size (nn,2).
first matrix is called indi:
0 0
1 2
3 4
5 0
6 7
8 9
second matrix is made in the first for loop shown and gives the following result:
-5 10.416
0 0
0 0
0 14.583
0 0
0 0
What Im trying to achieve is to get the second for loop to remove the rows of the second matrix in which both values are zeros. So what i need is just basically:
-5 10.416
0 14.583
The error I get is "index exceeds matrix dimensions" which is probably happening since the second for loop goes from 1 to nn, and as it cycles the matrix stops being of size (nn,2). Anyone have any ideas on how to get around this??
here's the code:
for ii=1:nn
if indi(ii,1)==0
reacc(ii,1)=nodos(ii,1);
else
reacc(ii,1)=0;
end
if indi(ii,2)==0
reacc(ii,2)=nodos(ii,2);
else
reacc(ii,2)=0;
end
end
for jj=1:nn
if (reacciones(jj,1)==0) & (reacciones(jj,2)==0)
reacciones(jj, :) = []
end
end

 채택된 답변

Roger Stafford
Roger Stafford 2014년 11월 12일

0 개 추천

To correct the problem you describe, do that last for-loop backwards:
for jj=nn:-1:1
if ....

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2014년 11월 12일

댓글:

2014년 11월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by