Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Reading in XLS data containing numbers&strings

Subject: Reading in XLS data containing numbers&strings

From: Catalin Eberhardt

Date: 18 May, 2011 15:20:04

Message: 1 of 4

Hello,

I have a bunch of XLS files containing numerical data, that I'd like to read into Matlab (using xlsread); the problem is that all of these files have header rows, and so I always get a row full of NaN's at the start of each matrix that I read a file into.

Also, the naming of the columns is different from file to file, so I actually need that header information to know what each of the columns represents.

I know Matlab doesn't work well with strings, but is there any way for the cells that contain strings to be read correctly into Matlab?

Many thanks for any replies!

Subject: Reading in XLS data containing numbers&strings

From: Sadik

Date: 18 May, 2011 15:37:03

Message: 2 of 4

Hi Catalin,

You should use all three outputs so that you can keep track of the NaN'ified strings.

[numeric,txt,raw] = xlsread('file.xls');

raw keeps everything you want: numeric and text.

Best.

Subject: Reading in XLS data containing numbers&strings

From: Andy

Date: 18 May, 2011 15:40:05

Message: 3 of 4

"Catalin Eberhardt" wrote in message <ir0o34$mc8$1@newscl01ah.mathworks.com>...
> Hello,
>
> I have a bunch of XLS files containing numerical data, that I'd like to read into Matlab (using xlsread); the problem is that all of these files have header rows, and so I always get a row full of NaN's at the start of each matrix that I read a file into.
>
> Also, the naming of the columns is different from file to file, so I actually need that header information to know what each of the columns represents.
>
> I know Matlab doesn't work well with strings, but is there any way for the cells that contain strings to be read correctly into Matlab?
>
> Many thanks for any replies!

Straight from the xlsread documentation:

[num, txt]= xlsread(filename, ...) returns numeric data in array num and text data in cell array txt. All cells in txt that correspond to numeric data contain the empty strin

or

[num, txt, raw] = xlsread(filename, ...) returns numeric and text data in num and txt, and unprocessed cell content in cell array raw, which contains both numeric and text data.

Subject: Reading in XLS data containing numbers&strings

From: Catalin Eberhardt

Date: 19 May, 2011 10:18:03

Message: 4 of 4

Many thanks for your replies, and apologies for obviously not having gone through the help for xlsread thoroughly enough!

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us