What is the difference between xlsfinfo and xlsread?

7 Ansichten (letzte 30 Tage)
Lexington Stoyell
Lexington Stoyell am 7 Feb. 2018
Kommentiert: Walter Roberson am 7 Feb. 2018
I currently have a code where the file is read in using xlsfinfo. Below I have attached a code that requires xlsread (I think anyway...it does not work when I use xlsfinfo and error codes "Expected to be a cell array, was char instead."). I am unsure whether functions within the rest of the code need specific information from xlsfinfo, or it xlsread would work just fine. If so I do not want to have to read in the file twice using the two file readers. Also I am new to xlsfinfo and would like an explanation of it and the difference between it and xlsread. Thank you!
[~,~,dat]=xlsread('Practice_AFT.xlsx');
%Finds the row and column where the word is...
[~,headerCol_Command] = find(cellfun(@(x)~isempty(strfind(x,'Command')),dat));
dat1=dat(:,headerCol_Command);%extracts the column for Command

Akzeptierte Antwort

Steven Lord
Steven Lord am 7 Feb. 2018
The xlsfinfo function returns some information about the spreadsheet whose name you specified as the input.
The xlsread function reads the data from the spreadsheet whose name you specified as the input.
To use an analogy, xlsfinfo tells you what cereal is in the box you're holding while xlsread pours you a bowl of that cereal. If you already know what cereal is in the box and you just want to eat, use xlsread. If it's dark in the kitchen and you want to make sure before you pour that you're holding a box of cereal not a box of dishwasher detergent, you should use xlsinfo first.
  3 Kommentare
Lexington Stoyell
Lexington Stoyell am 7 Feb. 2018
So then is it acceptable/ in good practice to use both xlsfinfo and xlsread?
Walter Roberson
Walter Roberson am 7 Feb. 2018
xlsinfo() is often not needed, as it is common to already know the sheet names, and good practice on xlsread() would be to use a try/catch block just in case reading the file failed anyhow. xlsinfo() can be slow, especially on xlsx files on OS-X or Linux.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by