Manipulation of multiple cell arrays
1 view (last 30 days)
Nikolaos Zafirakis on 23 Jul 2019
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".
Bob Thompson on 23 Jul 2019
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);