Manipulation of multiple cell arrays

1 vue (au cours des 30 derniers jours)
Nikolaos Zafirakis
Nikolaos Zafirakis le 23 Juil 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".
pic.jpg

Réponse acceptée

Bob Thompson
Bob Thompson le 23 Juil 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);
  3 commentaires
Bob Thompson
Bob Thompson le 23 Juil 2019
Modifié(e) : Bob Thompson le 23 Juil 2019
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
Nikolaos Zafirakis
Nikolaos Zafirakis le 23 Juil 2019
Thanks a lot that will do however if anyone reads this post and knows how to solve this without a loop please let me know!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by