MATLAB: I need to make a function that reads an excel file

excelfunctionxlsread

How do I read an Excel file into a function without hard coding it? I want to be able to put the file into the functionhandle with a predefined variable as the xlsx file, but i can't seem to make it work.

Best Answer

How about this
function [numbers, strings, raw] = MyXlsread(filename)
numbers = [];
strings = [];
raw = [];
if exist(filename, 'file')
[numbers, strings, raw] = xlsread(filename);
else
message = sprintf('File not found:\n%s', filename);
uiwait(warndlg(message));
end