MATLAB can't find my file
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
I'm trying to read in an excel spreadsheet and I can't get it to do it.
I put the spreadsheet in the MATLAB home directory, then I put this: -
M = xlsread('Psych_anon_mine.xlsx');
And I get the error message: -
??? Error using ==> xlsread at 214 XLSREAD unable to open file Psych_anon_mine.xlsx. File /Users/Tom**********/Documents/MATLAB/Psych_anon_mine.xlsx not found.
(The stars are just my last name)
Error in ==> Ass_2_data_A at 3 M = xlsread('Psych_anon_mine.xlsx');
Any help would be greatly appreciated
채택된 답변
Walter Roberson
2012년 12월 12일
0 개 추천
(Looks like you are using OS-X)
At the MATLAB command prompt, try
!ls ~/Documents/MATLAB/Psych_anon*
and see if it finds the file. Perhaps there is a hidden extension.
댓글 수: 14
Yes thanks that worked. I just copied and pasted the address from that and it's working now. Many thanks.
Walter Roberson
2012년 12월 12일
이동: Voss
2022년 11월 9일
Was there a hidden extension? Or was there a typo in the file name?
Alireza Kharazmi
2016년 7월 28일
Hi, I am also using OS and I have similar problem with Matlab. I have tried it but it gives me this error "No such file or directory". I would be grateful if you could help me.
Walter Roberson
2016년 7월 28일
Which directory is your spreadsheet in? What is your current directory at the time you give the xlsread() command? Please show the commands that you use to construct the file name, and your xlsread command.
Alireza Kharazmi
2016년 7월 28일
I am using importdata command for a txt file. In fact, when I use uigetfile it does not import the data but if I use importdata('filename') it works.
Stephen23
2016년 7월 28일
@Alireza Kharazmi: uigetfile does not import data, it returns the selected file name. This is clearly explained in the documentation.
Alireza Kharazmi
2016년 7월 28일
Sorry, I am not sure if I answered your question properly. I am confused now. I am using three open file with three different push buttons. I am starting from the same directory where .m file is placed. The first push button is uigetfile and then cd command to get into the directory of interest and then importdata some data. Second push buttons is another uigetfile and then importdata some other files. These two steps are okay. The third push button is a uigetfile but the file of interest is inside another folder in the current directory. At this point I get this error "Unable to open file.".
Walter Roberson
2016년 7월 28일
Instead of cd'ing around, you should use fullfile() to construct complete file names.
Alireza Kharazmi
2016년 8월 8일
My apologies for late response, thank you very much for your help Walter. My problem is fixed now.
Armando Torres
2022년 11월 9일
Hi Walter,
I am having a similar problem with mzxmlread. I am using OS-X and the 2022 version of Matlab. I am following the same syntax as online and I tried using your command code and it still told me that it couldn't find the file. I don't know what to do. Will you please help me out?
Best,
Armando
With the information you have given us, we cannot be sure that the file is intended to be in the current directory, or if it is intended to be in a different folder. If it is possibly in another folder you need to specify the path to the file, possibly using fullfile() to construct the path that is to be passed in.
[filename, filepath] = uigetfile('*.mzXML');
if isnumeric(filename); return; end %user cancel
fullname = fullfile(filepath, filename);
out = mzxmlred(fullname);
If the file intended to be in your current directory then you should verify that the file exists with that exact name, such as using
ls trial*
@Armando Torres try it this way
fullFileName = fullfile(pwd, 'trial1.mzxml');
if ~isfile(fullFileName)
warningMessage = sprintf('Error:\n"%s"\nwas not found. Please locate it.', fullFileName)
uiwait(warndlg(warningMessage));
% Have user browse for a file, from a specified "starting folder."
% For convenience in browsing, set a starting folder from which to browse.
startingFolder = pwd; % or 'C:\wherever';
if ~isfolder(startingFolder)
% 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, '*.mz*');
[baseFileName, folder] = uigetfile(defaultFileName, 'Select a file');
if baseFileName == 0
% User clicked the Cancel button.
return;
end
fullFileName = fullfile(folder, baseFileName)
end
out = mzxlmread(fullFileName)
Armando Torres
2022년 11월 10일
I’ll give it a try later on tonight! Thank you both so much. I will update you with what happens
Armando Torres
2022년 11월 10일
It worked! Thank you both
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
제품
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
