Remove values from cell array based on condition
显示 更早的评论
Hey
I have two cell arrays like this:
A= {[2,3,4,5,6]; [1,3,4,5,6,7,8] }
B= {NaN, 1,1,-0.9,0.8,[],[]; NaN, NaN, 0.9,-1,NaN,0.8,0.2}
I want to find indexes of values less than 0 and of NaN values in B like here in first row of B we will get 1 (for NaN) and 4 for (values less than zero) and for these indexes i want to remove values placed in A like value at index 1 in A is 2 so it will be removed and also 5 will be removed. Same for row 2. New matrix A will look like this:
NewA= {[3,4,6]; [4,7,8]}
Please help.
采纳的回答
更多回答(1 个)
José-Luis
2017-8-16
A= {[2,3,4,5,6]; [1,3,4,5,6,7,8] }
B= {NaN, 1,1,-0.9,0.8,[],[]; NaN, NaN, 0.9,-1,NaN,0.8,0.2}
result = cell(size(A));
dummy = cellfun(@(x) ~isempty(x) && ~isnan(x) && x >= 0 ,B,'UniformOutput', false);
for ii = 1:size(A,1)
result{ii} = A{ii}([dummy{ii,:}])
end
类别
在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!