Info

This question is closed. Reopen it to edit or answer.

Delete some matrix rows that contain zero values in some part

1 view (last 30 days)
Hello everyone,
I'm trying to use any function to eliminate some rows of my matrix as shown below
31251 31252 31261 31260 31372 31373 31382 31381 3 3 0 0 0 0
31252 31253 31262 31261 31373 31374 31383 31382 3 3 0 0 0 0
31253 31254 31263 31262 31374 31375 31384 31383 3 3 0 0 0 0
31254 31212 31213 31263 31375 31333 31334 31384 3 3 0 0 0 0
0 0 0 0 0 0 0 0 3 3 0 0 0 0
0 0 0 0 0 0 0 0 3 3 0 0 0 0
0 0 0 0 0 0 0 0 3 3 0 0 0 0
0 0 0 0 0 0 0 0 3 3 0 0 0 0
0 0 0 0 0 0 0 0 3 3 0 0 0 0
0 0 0 0 0 0 0 0 3 3 0 0 0 0
31260 31261 31270 31269 31381 31382 31391 31390 3 3 0 0 0 0
31261 31262 31271 31270 31382 31383 31392 31391 3 3 0 0 0 0
31262 31263 31272 31271 31383 31384 31393 31392 3 3 0 0 0 0
I want to Eliminate zero values that contains in column 1 to column 8 and get the result as
31251 31252 31261 31260 31372 31373 31382 31381 3 3 0 0 0 0
31252 31253 31262 31261 31373 31374 31383 31382 3 3 0 0 0 0
31253 31254 31263 31262 31374 31375 31384 31383 3 3 0 0 0 0
31254 31212 31213 31263 31375 31333 31334 31384 3 3 0 0 0 0
31260 31261 31270 31269 31381 31382 31391 31390 3 3 0 0 0 0
31261 31262 31271 31270 31382 31383 31392 31391 3 3 0 0 0 0
31262 31263 31272 31271 31383 31384 31393 31392 3 3 0 0 0 0
Please give me some suggestion
Thanks in advance.

Answers (1)

Ameer Hamza
Ameer Hamza on 30 Oct 2020
Edited: Ameer Hamza on 30 Oct 2020
Try this
idx = any(A(:,1:8), 2);
A = A(idx, :);
A = [
31251 31252 31261 31260 31372 31373 31382 31381 3 3 0 0 0 0
31252 31253 31262 31261 31373 31374 31383 31382 3 3 0 0 0 0
31253 31254 31263 31262 31374 31375 31384 31383 3 3 0 0 0 0
31254 31212 31213 31263 31375 31333 31334 31384 3 3 0 0 0 0
0 0 0 0 0 0 0 0 3 3 0 0 0 0
0 0 0 0 0 0 0 0 3 3 0 0 0 0
0 0 0 0 0 0 0 0 3 3 0 0 0 0
0 0 0 0 0 0 0 0 3 3 0 0 0 0
0 0 0 0 0 0 0 0 3 3 0 0 0 0
0 0 0 0 0 0 0 0 3 3 0 0 0 0
31260 31261 31270 31269 31381 31382 31391 31390 3 3 0 0 0 0
31261 31262 31271 31270 31382 31383 31392 31391 3 3 0 0 0 0
31262 31263 31272 31271 31383 31384 31393 31392 3 3 0 0 0 0];
idx = any(A(:,1:8), 2);
A = A(idx, :);
Result
>> A
A =
Columns 1 through 8
31251 31252 31261 31260 31372 31373 31382 31381
31252 31253 31262 31261 31373 31374 31383 31382
31253 31254 31263 31262 31374 31375 31384 31383
31254 31212 31213 31263 31375 31333 31334 31384
31260 31261 31270 31269 31381 31382 31391 31390
31261 31262 31271 31270 31382 31383 31392 31391
31262 31263 31272 31271 31383 31384 31393 31392
Columns 9 through 14
3 3 0 0 0 0
3 3 0 0 0 0
3 3 0 0 0 0
3 3 0 0 0 0
3 3 0 0 0 0
3 3 0 0 0 0
3 3 0 0 0 0

Community Treasure Hunt

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

Start Hunting!