error when using addpath (mac user)

8 次查看(过去 30 天)
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 个评论
Renee
Renee 2013-11-9
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.

请先登录,再进行评论。

采纳的回答

Jan
Jan 2013-11-10
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 个评论
Renee
Renee 2013-11-10
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

请先登录,再进行评论。

更多回答(1 个)

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

类别

Help CenterFile Exchange 中查找有关 Search Path 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by