XLSWRITE - into same folder location as M file
이전 댓글 표시
I want to store my M files on a USB stick for protability. Some of these M files create xlsx files as an output. I would like to store these in the same folder location as the M file which creates them. I used the usual xlswrite ('filename.xlsx', variable); but get an error:
Error using xlswrite (line 220)
Invoke Error, Dispatch Exception:
Source: Microsoft Excel Description: Microsoft Excel cannot access the file 'C:\WINDOWS\system32\38C41000'. There are several possible reasons:
• The file name or path does not exist.
• The file is being used by another program.
• The workbook you are trying to save has the same name as a currently open workbook.
Many thanks.
채택된 답변
추가 답변 (2개)
Azzi Abdelmalek
2013년 6월 6일
You should specify the folder when using xlswrite
xlswrite('yourolder/yourfile.xls',data)
댓글 수: 4
Vineet Guru
2013년 6월 6일
Azzi Abdelmalek
2013년 6월 6일
편집: Azzi Abdelmalek
2013년 6월 6일
Then use pwd to guet the current folder
yourfolder=pwd
xlswrite([ youfrolder '\yourfile.xls'],data)
Vineet Guru
2013년 6월 6일
Azzi Abdelmalek
2013년 6월 6일
편집: Azzi Abdelmalek
2013년 6월 6일
How are you running your m-file? your m-files, are not in the current folder? And I am not getting what the aim of what you are looking for
[p f] = fileparts(mfilename('fullpath'));
xlswrite([p '\excel filename.xls'], ...)
댓글 수: 3
Vineet Guru
2013년 6월 6일
Iain
2013년 6월 6일
mfilename('fullpath') grabs the path, and the filename of the m file (but not the .m bit)
Jan
2013년 6월 6일
편집: Image Analyst
2013년 6월 6일
fullfile(p, 'excel filename.xlsx') considers potentially existing trailing and OS depending file separators automatically.
카테고리
도움말 센터 및 File Exchange에서 App Building에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!