can you help me to correct this program i write it to remove the rows who The sum of its elements is zero

Respuestas (1)

For matrix a
a(~sum(a,2),:) = []

6 comentarios

friend i tryed it .its doesnt work .can you look again.its doesnt remove the rows just calculate rows elements
do you know other ways to remove rows who The sum of its elements is zero functions .....like that
Paolo
Paolo el 26 de Jun. de 2018
Editada: Paolo el 26 de Jun. de 2018
Works on my machine. (The sum is computed row wise.) What does your matrix look like?
@Ziad, Paolo's answer is the most efficient way of removing rows whose sum is zero. It is also correct, so coming up with other ways would be a waste of time, since they would all produce the same result.
So, if it doesn't work it's because either you're not asking the right thing or you're doing something wrong. For us to know what the problem is on your end, give us an example of input and the desired result.
Also DON'T use ans as a variable name. This is the default variable name but it's also a temporary, scratch variable that could be overwritten at any time unexpectedly so it's not something you should depend upon.
For that matter, don't use i or j (the imaginary number) as a variable either. Use k, row, ii, index, or some other name instead.
For that matter, don't use i or j (the imaginary number) as a variable either. Use k, row, ii, index, or some other name instead.
Or, don't use i,j as the imaginary number. Use 1i or 1j instead.

La pregunta está cerrada.

Preguntada:

el 26 de Jun. de 2018

Cerrada:

el 20 de Ag. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by