Ussing input to read an excel file
Show older comments
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
on 12 Jul 2023
0 votes
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.
.
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!