How do I get rid of NaNs in MATLAB?
excel, matlab, nan
Solution
Use ' isfinite ' function to get rid of all NaN and infinities
A=A(isfinite(A))
%create the cell array containing the column headers columnHeader = {'Column 1', 'Column 2', 'Column 3', 'Column 4', 'Column 5',' '};
%write the column headers first xlswrite('myFile1.xls', columnHeader );
% write the data directly underneath the column headers xlswrite('newFile.xls',M,'Sheet1','A2');
Problem
I have files which have many empty cells which appear as NaNs when I use `cell2mat`, but the problem is when I need to get the average values I cannot work with this as it shows error with NaN. In excel it overlooks NaN values, so how do I do the same in MATLAB? In addition, I am writing a file using `xlswrite`: ``` xlswrite('test.xls',M); ``` I have data in all rows except 1. How do I write: ``` M(1,:) = ('time', 'count', 'length', 'width') ``` In other words, I want `M(1,1)='time'`, `M(1,2)='count'`, and so on. I have data from `M(2,1)` to `M(10,20)`. How can I do this?