delete rows in a cell array
3 次查看(过去 30 天)
显示 更早的评论
having a cell array containing in 1st column a name of a country and in next column values, how can I delete rows containing 1 or more zeros values?
1 个评论
Stephen23
2019-1-29
@Anastasia Anastasiadou: please upload your data in a .mat file by clicking the paperclip button.
采纳的回答
madhan ravi
2019-1-29
编辑:madhan ravi
2019-1-29
C={'country1' 11 33 55 40
'country2' 22 0 0 0
'country3' 58 44 55 5 };
idx=cellfun(@all,C,'un',0);
C(~all(cell2mat(idx),2),:)=[]
10 个评论
madhan ravi
2019-1-29
编辑:madhan ravi
2019-1-29
Help us to help you! , that's why we ask you to upload the required files at he very beginning when you ask a question so that a fast solution can be provided.
更多回答(2 个)
Omer Yasin Birey
2019-1-29
编辑:Omer Yasin Birey
2019-1-29
Lets say your cell array's variable name is 'a'
a = a(all(cellfun(@(x)x~=0,a),2),:);
5 个评论
Omer Yasin Birey
2019-1-29
That should work
remZeros = a(all(cellfun(@(x)x~=0,a),2),:);
remZeros(2:end+1,:) = remZeros(1:end,:);
remZeros(1,:) = a(1,:);
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!