Cody

Problem 43751. Remove Missing Values from a Table or an Array

Solution 1100453

Submitted on 9 Jan 2017 by Jean-Marie Sainthillier
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
1 x = [1 3 NaN 6 NaN]; y_correct = [1 3 6]; assert(isequal(your_fcn_name(x),y_correct))

ans = 1 ans = 1 3 6

2   Pass
2 x = [1 3 NaN 6 NaN;6 3 1 5 2; NaN 1 2 3 4; 1:5; 5:-1:1]; y_correct = [6 3 1 5 2; 1:5; 5:-1:1]; assert(isequal(your_fcn_name(x),y_correct))

ans = 2 ans = 6 3 1 5 2 1 2 3 4 5 5 4 3 2 1

3   Pass
3 x = [1 3 NaN 6 NaN]; y_correct = [1 3 6]; assert(isequal(your_fcn_name(x),y_correct))

ans = 3 ans = 1 3 6

4   Pass
4 x = table(categorical({'';'F';'M'}),[45;32;NaN],{'';'CA';'MA'},[6051;7234;NaN],... 'VariableNames',{'Gender' 'Age' 'State' 'ID'}) y_correct = table(categorical({'F'}),[32],{'CA'},[7234],... 'VariableNames',{'Gender' 'Age' 'State' 'ID'}) assert(isequal(your_fcn_name(x),y_correct))

ans = 4 x = <strong> Gender </strong><strong> Age</strong><strong> State</strong><strong> ID </strong> <strong>___________</strong> <strong>___</strong> <strong>_____</strong> <strong>____</strong> <undefined> 45 '' 6051 F 32 'CA' 7234 M NaN 'MA' NaN y_correct = <strong>Gender</strong><strong> Age</strong><strong> State</strong><strong> ID </strong> <strong>______</strong> <strong>___</strong> <strong>_____</strong> <strong>____</strong> F 32 'CA' 7234 ans = <strong>Gender</strong><strong> Age</strong><strong> State</strong><strong> ID </strong> <strong>______</strong> <strong>___</strong> <strong>_____</strong> <strong>____</strong> F 32 'CA' 7234

5   Pass
5 dblVar = [2;3;5;7;9;11]; singleVar = single([1;NaN;5;7;9;11]); cellstrVar = {'one';'three';'four';'seven';'nine';'eleven'}; charVar = ['A';'C';'E';'G';'I';'J']; categoryVar = categorical({'red';'yellow';'blue';'violet';'';'ultraviolet'}); m = [1:2:10]; dateVar = [datetime(2015,m,15) NaT]'; x = table(dblVar,singleVar,cellstrVar,charVar,categoryVar,dateVar) dblVar = [2;5;7]; singleVar = single([1;5;7]); cellstrVar = {'one';'four';'seven'}; charVar = ['A';'E';'G']; categoryVar = categorical({'red';'blue';'violet'}); m = [1 5 7]; dateVar = [datetime(2015,m,15)]'; y_correct = table(dblVar,singleVar,cellstrVar,charVar,categoryVar,dateVar) assert(isequal(your_fcn_name(x),y_correct))

ans = 5 x = <strong>dblVar</strong><strong> singleVar</strong><strong> cellstrVar</strong><strong> charVar</strong><strong> categoryVar</strong><strong> dateVar </strong> <strong>______</strong> <strong>_________</strong> <strong>__________</strong> <strong>_______</strong> <strong>___________</strong> <strong>___________</strong> 2 1 'one' A red 15-Jan-2015 3 NaN 'three' C yellow 15-Mar-2015 5 5 'four' E blue 15-May-2015 7 7 'seven' G violet 15-Jul-2015 9 9 'nine' I <undefined> 15-Sep-2015 11 11 'eleven' J ultraviolet NaT y_correct = <strong>dblVar</strong><strong> singleVar</strong><strong> cellstrVar</strong><strong> charVar</strong><strong> categoryVar</strong><strong> dateVar </strong> <strong>______</strong> <strong>_________</strong> <strong>__________</strong> <strong>_______</strong> <strong>___________</strong> <strong>___________</strong> 2 1 'one' A red 15-Jan-2015 5 5 'four' E blue 15-May-2015 7 7 'seven' G violet 15-Jul-2015 ans = <strong>dblVar</strong><strong> singleVar</strong><strong> cellstrVar</strong><strong> charVar</strong><strong> categoryVar</strong><strong> dateVar </strong> <strong>______</strong> <strong>_________</strong> <strong>__________</strong> <strong>_______</strong> <strong>___________</strong> <strong>___________</strong> 2 1 'one' A red 15-Jan-2015 5 5 'four' E blue 15-May-2015 7 7 'seven' G violet 15-Jul-2015