Removing specific rows from a matrix where its corresponding element in another column is zero.
1 次查看(过去 30 天)
显示 更早的评论
Hi All,
I've a matrix abc, I want to remove those columns from it where its corresponding element in third column is zero.
For example , I should be getting the answer as:
ans =[ 1 2 3 ; 4 5 6; 1 5 8; 2 6 9 ; 3 5 9;]
Below is my attempt where I'm getting out of bound error for index position 4 which is obvious as the size is 8 x 3.
abc = [ 1 2 3 ; 4 5 6; 3 4 0 ; 1 5 8; 2 6 9 ; 3 5 9; 2 6 0; 7 7 0;]
sz = size(abc)
row =sz(1)
col = sz(2)
for ii = 1: row
for jj = 1:col
if abc(ii,jj) ==0
abc(:,jj) = [];
jj = jj+1
else
ii = ii+1
end
end
end
Please correct my code.
Thanks in advance!
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!