Ussing input to read an excel file

Hello, I am attempting to create a script than can be used by multiple people that gives users the abiity to input an excel and execute the necessary functions. The goal is to create a generic script that a user can define a file in the command window using the input function, which then can be read into the workspace. Currently, I have this basic process:
tdms = "Enter file name: ";
file = input(tdms, "s");
datafile = xlsread(file)
The file is able to be inputted and read, but it returns mostly NaN, due to the spreadsheet being mostly words. Is there a way to import both the wording and numeric data for analysis?

Answers (1)

Star Strider
Star Strider on 12 Jul 2023
There are several options. Without having the file to work with, readtable and readcell could be appropriate.
The xlsread function has three outputs, the first being a numeric matrix, the second being a string or character array, and the third being a cell array of everything in the file.
Perhaps something like this:
[datafile,s,cellarray] = xlsread(file)
would be worth considering. See if the third output, (‘cellarray’ here), has the information you want.
.

Products

Release

R2018b

Asked:

on 12 Jul 2023

Answered:

on 12 Jul 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!