user768199
user768199

Reputation: 25

Octave - Excel - Xlsread reads Nan instead of text

The Universities spread sheat in Excel include:

ID & University Name
0    Mechanical Engineering
1    Civil Engineering

filename = 'test.xlsx';
sheet = 'Universities';
xlRange = 'A2:B31'; 
UniversityNames = xlsread(filename,sheet,xlRange);

but when I display universitynames matrix. I can see ID number but university Name is displayed as 'NaN'. I need to see names of university in this UniversityNames matrix. How can I fix this? OS is Windows 10, Excel 2010.

Upvotes: 2

Views: 3692

Answers (1)

sco1
sco1

Reputation: 12214

Octave's xlsread function has multiple outputs. The first output returned is the numeric data from the input range, which is what you're currently reading in as UniversityNames. The optional second output returns the text strings from the input range, which I'm assuming is what you're looking for. You can also utilize the optional third output, which returns a cell array of the raw strings from the input range.

filename = 'test.xlsx';
sheet = 'Universities';
xlRange = 'A2:B31'; 
[UniversityNames_numeric, UniversityNames_textual] = xlsread(filename, sheet, xlRange);

Or

filename = 'test.xlsx';
sheet = 'Universities';
xlRange = 'A2:B31'; 
[~, ~, rawdata] = xlsread(filename, sheet, xlRange);

Upvotes: 2

Related Questions