excel - writetable replace NaN with blanks in Matlab -


given matlab table contains many nan, how can write table excel or csv files nan replaced blanks?

i use following function:

t = table(nan(5,2),'variablenames',{'a','c'})  writetable(t, filename) 

i not want replace zeros. want output file:

  1. has blanks nan ,
  2. that variable names included in output.

you need xlswrite that. replaces nans blanks itself. use table2cell or combination of table2array , num2cell convert table cell array first. use variablenames property of table retrieve variable names , pad them cell array.

data= [t.properties.variablenames; table2cell(t)]; %or data= [t.properties.variablenames; num2cell(table2array(t))]; xlswrite('output',data); 

sample run for:

t = table([1;2;3],[nan; 410; 6],[31; nan; 27],'variablenames',{'one' 'two' 'three'})  t =    3×3 table      1    2    3     ___    ___    _____      1      nan     31       2      410    nan       3        6     27   

yields:

output


although above solution simpler in opinion if want use writetable then:

tmp = table2cell(t);             %converting table cell array tmp(isnan(t.variables)) = {[]};  %replacing nan entries [] t = array2table(tmp,'variablenames',t.properties.variablenames); %converting table writetable(t,'output.csv');      %writing csv file 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -