How do I use the fillmissing function in a table containing char elements? I am trying to use the 'previous' method.

1 Ansicht (letzte 30 Tage)
I have been using this command to no avail:
fillmissing(T1,"previous","DataVariables", @ischar)
  2 Kommentare
Image Analyst
Image Analyst am 17 Mai 2023
You forgot to attach your table T1, so we can't debug it.
If you have any more questions, then attach your data in a .mat file and code to read it in with the paperclip icon after you read this:
save('answers.mat', 'T1');
Steven Lord
Steven Lord am 17 Mai 2023
What does "to no avail" mean in this context?
  • Do you receive warning and/or error messages? If so the full and exact text of those messages (all the text displayed in orange and/or red in the Command Window) may be useful in determining what's going on and how to avoid the warning and/or error.
  • Does it do something different than what you expected? If so, what did it do and what did you expect it to do?
  • Did MATLAB crash? If so please send the crash log file (with a description of what you were running or doing in MATLAB when the crash occured) to Technical Support so we can investigate.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Cris LaPierre
Cris LaPierre am 18 Mai 2023
Your syntax is fine. You might need to standardize your missing values first. For char arrays, missing is ' '.
dblVar = [NaN;3;Inf;7;9];
cellstrVar = {'one';'three';'';'N/A';'nine'};
charVar = ['A';'C';'E';' ';'I'];
categoryVar = categorical({'red';'yellow';'blue';'violet';''});
A = table(dblVar,cellstrVar,charVar,categoryVar)
A = 5×4 table
dblVar cellstrVar charVar categoryVar ______ __________ _______ ___________ NaN {'one' } A red 3 {'three' } C yellow Inf {0×0 char} E blue 7 {'N/A' } violet 9 {'nine' } I <undefined>
C = fillmissing(A,"previous","DataVariables", @ischar)
C = 5×4 table
dblVar cellstrVar charVar categoryVar ______ __________ _______ ___________ NaN {'one' } A red 3 {'three' } C yellow Inf {0×0 char} E blue 7 {'N/A' } E violet 9 {'nine' } I <undefined>
  1 Kommentar
Peter Perkins
Peter Perkins am 5 Jun. 2023
Also, you probably do not have a char variable in your table, you probably have a cell array containing char rows.
1) Use string if at all possible.
2) Use var names or indices for the DataVariables parameter, not @ischar.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Data Type Identification finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by