Info
此问题已关闭。 请重新打开它进行编辑或回答。
Delete some matrix rows that contain zero values in some part
1 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(1 个)
Ameer Hamza
2020-10-30
编辑:Ameer Hamza
2020-10-30
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
0 个评论
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!