Removing <missing> from cell arrays

81 vues (au cours des 30 derniers jours)
Arthur Romeu
Arthur Romeu le 24 Jan 2020
Commenté : Davindra Usov le 7 Juil 2022
Hello everyone!
I hope you are doing well.
I am currently trying to remove missing entries from the cell array 'InfoStatus_dias', which you can find attached here. My original attempt to do so is as follows:
for k = 1:size(Datas_tratado,1)
for j = 1:14
rmmissing(InfoStatus_dias{k,1}{j,1});
end
end
Only to return error "Conversion of element 1 from <missing> to character vector is not supported."
Then I tried doing like so:
for k = 1:size(Datas_tratado,1)
rmmissing(InfoStatus_dias{k,1}{:,1});
end
But it returned the same error :(
I am struggling to find where my thinking is wrong while using this loop, and... well, could you shine a light on this matter?
Thanks in advance!
Arthur.

Réponse acceptée

Guillaume
Guillaume le 24 Jan 2020
Modifié(e) : Guillaume le 24 Jan 2020
Note that, as with most matlab functions, calling rmmissing without assigning its output to anything is a big waste of time. You're just throwing away whatever the function does.
The easiest way to do what I assume you want:
newInfoStatus = cellfun(@rmmissing, InfoStatus_dias, 'UniformOutput', false);
The loop equivalent of the above line, if you don't like cellfun:
newInfoStatus = cell(size(InfoStatus_dias));
for k = 1:numel(InfoStatus_dias)
newInfoStatus{k} = rmmissing(InfoStatus_dias{k}); %I recommend that you use 1D indexing in vector, {k} instead of {1,k} or {k, 1}
end
  2 commentaires
Arthur Romeu
Arthur Romeu le 24 Jan 2020
Thanks a bunch!!
That's exactly what I wanted to do. I'm going to read more about cellfun :)
Best regards,
Arthur.
Davindra Usov
Davindra Usov le 7 Juil 2022
What if the cell array 'InfoSatus_dias' is e.g. a 4x10 cell array where each individual cell is a 40x1 column vector? how would you go about removing all missing entries from each of these?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Data Type Conversion dans Help Center et File Exchange

Produits


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by