How to ignore NaN in a string cell

5 vues (au cours des 30 derniers jours)
Daneisha Blair
Daneisha Blair le 24 Sep 2021
Hi,
I have a cell array called test2 that contains some NaN and strings in each column, see attached image below.
I would like to create a loop where I can loop through test2 and ignore the NaN columns. The issue I am having is NaN characteristic is double and the if statement I created, if (cellfun(@(x) any(isnan(x)),test{i},'UniformOutput',false)), gives this error input#2 expected to be a cell array, was double instead.
Side note: i is the indices, for example i=1:1590.
Any help is very much appreciated.

Réponse acceptée

Sulaymon Eshkabilov
Sulaymon Eshkabilov le 25 Sep 2021
Modifié(e) : Sulaymon Eshkabilov le 25 Sep 2021
A simple answer is e.g.:
TEST = test(cellfun('isclass', test, 'char')) % All NANs removed
An alternative solution is e.g.:
test(cellfun(@(test) any(isnan(test)),test)) = []
  2 commentaires
Daneisha Blair
Daneisha Blair le 25 Sep 2021
Thank you!
Sulaymon Eshkabilov
Sulaymon Eshkabilov le 26 Sep 2021
Most welcome!!!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by