2

I want to read in some data from excel into Matlab say a 3x10 matrix. I need to distinguish whether the some cells are empty or blank in the read data. If empty, delete the row, if zero leave the matrix unchanged.

I am facing two problems with this: Matlab automatically truncates the leading empty cells in the matrix but leaves the empty cells within. Automatically resizing the matrix/array.

Mia
  • 171
  • 1
  • 12
  • Are you talking about a matrix or a cell array? A Matrix can't have empty elements. Can you give some example data and the expected output? – Daniel Mar 22 '14 at 22:27

1 Answers1

2

Imagine you have the following excel spreadsheet:

enter image description here

xlsread will read the sheet and fill empty cells with NaN:

A = xlsread('data.xlsx')

A =

     9     2     1
     3     9     8
     0   NaN     7
     3     4     0

Finally you just need to filter out the rows containing NaNs:

A = A(find(~any(isnan(A),2)),:)

A =

     9     2     1
     3     9     8
     3     4     0
Robert Seifert
  • 25,078
  • 11
  • 68
  • 113