Modifying matrix with if statement
Afficher commentaires plus anciens
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
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!