MATLAB: How to remove the NaN entries of a matrix returned by Excel Link 2.2.1 (R14SP1)

7emptyentriesexcellinkMATLABmlputmatrixnanr14rowsSpreadsheet Link

I used MLPutMatrix in Excel Link to transfer data from Excel to MATLAB. I would now like to remove all of the empty rows that are returned as NaN entries in MATLAB.

Best Answer

There is no quick way in MATLAB other than using the ISNAN command to compare each element of a matrix returned by MLPutMatrix and remove the NaN when ISNAN is true.
Another way to work around this problem is to use a macro in Excel VBA to remove all empty rows as follows:
Sub delteemptyrow()
On Error Resume Next ' In case there are no blanks
Columns("A:A").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
ActiveSheet.UsedRange 'Resets UsedRange for Excel
End Sub
If you add this as a macro in the Excel Workbook you will be able to delete empty rows.