Sanchit
Sanchit

Reputation: 3289

Best way to import numeric and non-numeric data (string) from an excel file into MATLAB?

I want to know the best way of importing both number and non-numeric data (which is string in the present case) from an excel file into MATLAB? By best (or better) way, I mean all the data together in a variable (or data structure).

First, I tried uiopen(filename) function which opens a wizard and from there, I can import the data into a MATLAB variable. However, problem here is that it replaces all the non-numeric data with zeros which is not required. I later on, found that this function calls another function, named xlsread(filename), which is another way (actual way) of importing excel file.

Second (last) way that I tried (which seems to be better) is to use function called importdata(filename) which imports both numeric and non-numeric data into separate structure variables.

However, I am wondering if there exists some other way(s) to import everything into a single variable or data structure?

Upvotes: 0

Views: 2369

Answers (1)

am304
am304

Reputation: 13876

xlsread is the correct way to import data from Excel spreadsheets,both numeric and non-numeric data. Check the documentation:

[num,txt,raw] = xlsread(___) additionally returns the text fields in cell array txt, and the unprocessed data (numbers and text) in cell array raw using any of the input arguments in the previous syntaxes. If xlRange is specified, leading blank rows and columns in the worksheet that precede rows and columns with data are returned in raw.

Upvotes: 2

Related Questions