error when using addpath (mac user)

28 views (last 30 days)
Renee
Renee on 8 Nov 2013
Commented: Renee on 10 Nov 2013
Hello,
I am trying to import data from excel into matlab using xlsread and xlsfinfo. It was working while I had the excel file in the MATLAB folder, but now that I've moved it to a different folder it doesn't work unless I go into the folder using Matlab's Current Folder Window, select the folder and then select Add to Path -> Selected Folders and Subfolders.
The excel file I would like to import data from is called 'Cell tracks summary - micrometres.xlsx'.
If I drag this file into terminal I get the path: /Volumes/Hard\ Drive\ 2/PhD\ Results/Excel\ Spreadsheets/Cell\ tracks\ -\ Transplantations/Bipolar\ phase/Cell\ tracks\ summary\ -\ micrometres.xlsx
I have tried adding the above into the search path using addpath: addpath('/Volumes/Hard\ Drive\ 2/PhD\ Results/Excel\ Spreadsheets/Cell\ tracks\ -\ Transplantations/Bipolar\ phase');
But I get the following message: Warning: Name is nonexistent or not a directory: /Volumes/Hard\ Drive\ 2/PhD\ Results/Excel\ Spreadsheets/Cell\ tracks\ -\ Transplantations/Bipolar\ phase. > In path at 110 In addpath at 87
Similarly, if I enter: [type,sheetname] = xlsfinfo('/Volumes/Hard\ Drive\ 2/PhD\ Results/Excel\ Spreadsheets/Cell\ tracks\ -\ Transplantations/Bipolar\ phase/Cell\ tracks\ summary\ -\ micrometres.xlsx')
I get the error message: Error using validpath>getFullName (line 74) File '/Volumes/Hard\ Drive\ 2/PhD\ Results/Excel\ Spreadsheets/Cell\ tracks\ -\ Transplantations/Bipolar\ phase/Cell\ tracks\ summary\ -\ micrometres.xlsx' not found.
Error in validpath (line 29) filenameOut = getFullName(filename);
Error in xlsfinfo (line 45) filename = validpath(filename);
Would anyone know of an easy way to add the folder to the search path, so that I don't have to go into the folder manually every time I want to import data from that folder?
Thank you.
Best Renee
  1 Comment
Renee
Renee on 9 Nov 2013
Thank you for your reply.
However, I don't think it is the answer I am looking for.
I know that xlsread and xlsfinfo works fine if I keep the Excel file in the MATLAB folder (which is the Current Folder when I launch Matlab) or if I manually go to the folder the Excel file is located in and add that folder to my search path. However, for organisational reasons I'd rather keep my Excel file on a different hard drive, in a different folder. I was wondering if there was a way for Matlab to import data from my Excel file without me having to manually go to the folder and add it to my search path.
Sorry if my initial question was not clear. Hope this clarifies it better.

Sign in to comment.

Accepted Answer

Jan
Jan on 10 Nov 2013
Try to insert the spaces without the escape characters:
addpath(['/Volumes/Hard Drive 2/PhD Results/Excel Spreadsheets/Cell tracks - ', ...
'Transplantations/Bipolar phase']);
But adding a folder to the path only to read a file from there is not efficient. Better use the absolute path of the file for the import.
  1 Comment
Renee
Renee on 10 Nov 2013
Dear Jan,
Thank you. Once I take out the escape characters both using addpath to add the folder and importing using the absolute path of the file works.
Best Renee

Sign in to comment.

More Answers (1)

vaishali
vaishali on 8 Nov 2013
Keep the file in current folder, don't use add path.

Categories

Find more on Search Path in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!