numbering rows and then using these numbers for another vector of equal n dimensions

1 次查看(过去 30 天)
If I have a matrix for example
A = [ 1 2 3; 1 2 5; 0 55 8; 0 0 0; 7 8 9; 4 0 5; 0 0 0] and I have a vector
B = [ 1; 2; 3; 4; 5; 6; 7].
(please note these are small for simplicity but my actual matrices and vectors are much bigger)
Now say I wanted to record the row numbers at which all three columns contained zeros and then replace the numbers in B at these particular rows with zero also so I would be left with
B = [1; 2; 3; 0; 5; 6; 0]
How would I do that. I think I need to use the ind2sub function but I cant get my head around how to do this
many thanks in advance :)

采纳的回答

Walter Roberson
Walter Roberson 2013-3-6
B( ~any(A,2) ) = 0;
  3 个评论
Azzi Abdelmalek
Azzi Abdelmalek 2013-3-6
This is not right
A = [ 1 2 3; 1 2 5; 0 55 8; 0 0 0; 7 8 9; 4 0 5; 0 0 0]
B = [ 1; 2; 3; 4; 5; 6; 7]
B( ~any(A,2) ) = 0
B =
1
2
3
0
5
6
0

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by