XLSWRITE - into same folder location as M file

3 次查看(过去 30 天)
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.

采纳的回答

Vineet Guru
Vineet Guru 2013-6-6
Thanks guys for your attempts. Your help is most appreciated.
I eventually stumbled upon the "uigetfile" instruction as with just a one click on the m file of interest in a folder, and the uigetfile picks up the folder + filename. I then stripped the filename and retained the folder.
  2 个评论
Walter Roberson
Walter Roberson 2013-6-6
If you just want the directory, then uigetdir() would be more appropriate.
Iain
Iain 2013-6-6
If you know the name of the files, you could use "which" to do it automatically as well.

请先登录,再进行评论。

更多回答(2 个)

Azzi Abdelmalek
Azzi Abdelmalek 2013-6-6
You should specify the folder when using xlswrite
xlswrite('yourolder/yourfile.xls',data)
  4 个评论
Vineet Guru
Vineet Guru 2013-6-6
The pwd instruction points to C:\windows\system32, which is not where my M file is.
Azzi Abdelmalek
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

请先登录,再进行评论。


Iain
Iain 2013-6-6
编辑:Iain 2013-6-6
[p f] = fileparts(mfilename('fullpath'));
xlswrite([p '\excel filename.xls'], ...)
  3 个评论
Iain
Iain 2013-6-6
mfilename('fullpath') grabs the path, and the filename of the m file (but not the .m bit)
Jan
Jan 2013-6-6
编辑:Image Analyst 2013-6-6
fullfile(p, 'excel filename.xlsx') considers potentially existing trailing and OS depending file separators automatically.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by