How to use fillmissing with table variables of type cell
    5 views (last 30 days)
  
       Show older comments
    
Hello,
I simply want to replace all empty cells ([]) by '99' in the table attached but only for the variables that begin with Q_. I get the following error however: Table variables of type cell are not supported.How do I get around that ?
all_vars = T1.Properties.VariableNames;
index = find(strncmp(all_vars, 'Q_', 2));
T1(:, index) = fillmissing(T1(:, index), 'constant', '99')
Thank you,
0 Comments
Answers (1)
  Guillaume
      
      
 on 29 Oct 2019
        Well, you're a funny one! 
You've asked a very similar question. You were given two answers, one of which used fillmissing to do exactly what you're asking now, but you accepted the other answer. 
Note that my answer used a simpler way of finding the data variables starting with Q_. For a start the find serves no purpose in the code you show. You'd get the exact same result using
index = strncmp(all_vars, 'Q_', 2);  %no need for find, you can use the logical vector directly
T(:, index) = ...
but using startsWith as per my answer is even simpler than strncmp.
2 Comments
  Guillaume
      
      
 on 29 Oct 2019
				Which version of matlab are you using?
I don't get any error using R2019b:
>> a = {'A'; 'B'; 'C'};
o = {'A'; '[]'; 'C'};
Q_y = {'1'; '[]'; '3'};
T1 = table(Q_x, a, o, Q_y)
T1 =
  3×4 table
     Q_x        a        o        Q_y  
    ______    _____    ______    ______
    {'1' }    {'A'}    {'A' }    {'1' }
    {'[]'}    {'B'}    {'[]'}    {'[]'}
    {'3' }    {'C'}    {'C' }    {'3' }
>> missinglocs = ismissing(T1, '[]'); 
newt = fillmissing(T1, 'constant', '-99', 'DataVariables', startsWith(T1.Properties.VariableNames, 'Q_'), 'MissingLocations', missinglocs)
newt =
  3×4 table
      Q_x        a        o         Q_y  
    _______    _____    ______    _______
    {'1'  }    {'A'}    {'A' }    {'1'  }
    {'-99'}    {'B'}    {'[]'}    {'-99'}
    {'3'  }    {'C'}    {'C' }    {'3'  }
See Also
Categories
				Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!