What is the difference between xlsfinfo and xlsread?

조회 수: 9 (최근 30일)
Lexington Stoyell
Lexington Stoyell 2018년 2월 7일
댓글: Walter Roberson 2018년 2월 7일
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
Lexington Stoyell 2018년 2월 7일
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에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by