What is the difference between xlsfinfo and xlsread?

3 次查看(过去 30 天)
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

采纳的回答

Steven Lord
Steven Lord 2018-2-7
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 个评论
Lexington Stoyell
So then is it acceptable/ in good practice to use both xlsfinfo and xlsread?
Walter Roberson
Walter Roberson 2018-2-7
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Import from MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by