我在一个1.4MB的excel文件上使用xlsread。在运行m代码几次之后,我开始注意到一些奇怪的行为。
我觉得matlab没有清理它的文件句柄。使用角到角读取数据的更新代码使用以下两行
prs = xlsread(file, 'data2','A2:C550');
elm = xlsread(file, 'element','A2:C65536');任务管理器在调用两个函数之后显示两个大型EXCEL.EXE*32文件。我试过
clear
clear all
close all
fclose('all')
fclose(0); fclose(1); fclose(2)等等,我关闭matlab,他们仍然是开放的。
在试图重新启动而没有结果的情况下,做了更多的窥探。
xlsread使用excel填充似乎是服务器来读取信息。
Excel = actxserver('excel.application');清理工作看起来就应该在这里进行
cleanUp = onCleanup(@()xlsCleanup(Excel, file));
[numericData, textData, rawData, customOutput] = xlsreadCOM(file, sheet, range, Excel, customFun);后面跟着一个
clear cleanUp; 在节目的后面。研究表明,这是为了运行一个名为xlsCleanup的清理函数。复制这里的文件以供参考。
function xlsCleanup(Excel, filePath)
try %#ok<TRYNC> - Suppress any exception
%Turn off dialog boxes as we close the file and quit Excel.
Excel.DisplayAlerts = 0;
%Explicitly close the file just in case. The Excel API expects
%just the filename and not the path. This is safe because Excel
%also does not allow opening two files with the same name in
%different folders at the same time.
[~, n, e] = fileparts(filePath);
fileName = [n e];
Excel.Workbooks.Item(fileName).Close(false);
end
Excel.Quit;
end首先,它不加警告地捕获异常。我查过了,但代码没有抛出异常。看来这条线
Excel.Workbooks.Item(fileName).Close(false);只是没有结束这个过程。我不知道在这个功能之外是什么导致了这个问题(不能再介入了),网络上也没有提到它的问题。请帮我解释一下这种行为。占据了我所有的记忆
发布于 2013-01-30 18:33:17
仍然没有解决matlab的问题。这就是我用来关闭在运行文件几次之后仍然打开的100万个进程的内容。
在Cygwin:
ps -W | grep EXCEL | cut -c -9 | xargs /bin/kill -f发布于 2013-01-07 15:38:53
范围参数也适用于角点。来自xlsread的文档
num = xlsread(filename,sheet,xlRange)使用语法' C1 : C2‘指定xlRange,其中C1和C2是定义要读取区域的两个相反的角。例如,' D2 : H4‘表示工作表上两个角D2和H4之间的3×5矩形区域。xlRange输入不区分大小写,并使用A1引用样式(参见Excel )。
这意味着你可以做:
xlsread(file, 'element', 'A2:C65536');发布于 2014-03-13 09:12:21
这对我有用。
system('taskkill /F /IM EXCEL.EXE');https://stackoverflow.com/questions/14198978
复制相似问题