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

1 次查看(过去 30 天)
I have been using this command to no avail:
fillmissing(T1,"previous","DataVariables", @ischar)
  2 个评论
Image Analyst
Image Analyst 2023-5-17
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 2023-5-17
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.

请先登录,再进行评论。

回答(1 个)

Cris LaPierre
Cris LaPierre 2023-5-18
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 个评论
Peter Perkins
Peter Perkins 2023-6-5
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Data Type Identification 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by