Manipulation of multiple cell arrays
1 次查看(过去 30 天)
显示 更早的评论
I have two questions one to improve my code and the other to perform an operation. I have a series of cell arrays and they are divided into groups as seen in the figure.
1) I currently need to filter out some measurements I found the below two pieces of code effective I was wondering how I could add and & into the expression to perform what I need in one go. Task is to filter out any measurement of all the column six in all cell arrays which are larger than 1.1 and smaller than 0.9.
O = cellfun(@(n) n(n(:,6)>=0.9,:),Bb,'UniformOutput',false);
L = cellfun(@(n) n(n(:,6)<=1.1,:),O,'UniformOutput',false);
2) After the previous two operations, I manage to filter out any lines having the criteria I do not need. Next I want to manipulate column five within each cell array such that it becomes a kind of counter for each cell thus I desire column five to contain 0,1,2,3,4,5,6,7...... for each cell and repeat at the next one starting at 0 again. I highlighted column five of the first cell array below “this figure is the result of operations in step one".
0 个评论
采纳的回答
Bob Thompson
2019-7-23
1) You don't want an & for this type of logic, because you want to remove anything that is less than 0.9, OR greater than 1.1. If you are looking for things which are less than 0.9 AND greater than 1.1, then you are looking for an impossible condition, and will not filter any numbers out because both conditions cannot be true at the same time. Use | or || for 'or,' and & or && for 'and.'
O = cellfun(@(n) n(n(:,6)>=0.9 | n(:,6)<=1.1,:),Bb,'UniformOutput',false);
2) I'm a bit confused what you're looking for here. I see that you're looking to sort the elements in ascending order, but I don't entirely understand how the repetition comes into play. Are you referring to repeating the sort for each cell? That type of operation should look something like the following:
O = cellfun(@(n) sortrows(n,5),O,'UniformOutput',0);
3 个评论
Bob Thompson
2019-7-23
编辑:Bob Thompson
2019-7-23
Hmm, because you're looking to replace specific parts of the cells, I think you might have to resort to a for loop. I'm not entirely sure how to do a replacement like that with something like cellfun.
for i = 1:size(O,1)
O{i}(:,5) = [1:size(O{i},1)];
end
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!