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 :)
0 个评论
采纳的回答
Walter Roberson
2013-3-6
B( ~any(A,2) ) = 0;
3 个评论
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 Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!