MATLAB: How to read an excel file and plot graphs

excel file

fileName = 'test.xls';
a=xlsread(fileName);
These commands are not working for me. Can anyone help? I get an error that the file not found.

Best Answer

'test.xls' is not in your current folder. Perhaps it's really called 'test.xlsx' or perhaps it's in a different folder. You can specify the folder it lives in and then use fullfile() to create the full file name.
folder = 'c:/whatever'
fullFileName = fullfile(folder, 'test.xls');
a = xlsread(fullFilename);
OR use the following to have the user manually locate it:
% Have user browse for a file, from a specified "starting folder."
% For convenience in browsing, set a starting folder from which to browse.
startingFolder = 'C:\Program Files\MATLAB';
if ~exist(startingFolder, 'dir')
% If that folder doesn't exist, just start in the current folder.
startingFolder = pwd;
end
% Get the name of the file that the user wants to use.
defaultFileName = fullfile(startingFolder, '*.xl*');
[baseFileName, folder] = uigetfile(defaultFileName, 'Select a file');
if baseFileName == 0
% User clicked the Cancel button.
return;
end
fullFileName = fullfile(folder, baseFileName)
a = xlsread(fullFilename);