【发布时间】:2023-04-11 00:55:02
【问题描述】:
我想这样做是因为否则我会用完内存来将值保存在矩阵中,因为矩阵的维度会增加。
例如,
for a=1:10000
for b=1:10000
M(a,b)=rand;
end
end
这里,系统内存不足,因为它无法存储 10000x10000 矩阵。
所以,我想继续将 for 循环中的 (a,b)'th 值写入 csv 文件(或 xls 文件等)的第 (a,b)'th 单元格。我该怎么做?
我想要这样的东西:
for a=1:10000
for b=1:10000
xlswrite1('file.xls',a,b,rand); % better if I can get a solution with csvwrite, as I prefer CSVs to work with
end
end
但这显然行不通。它给出的错误是:
Error using evalin
Undefined function or variable 'Excel'.
Error in xlswrite1 (line 2)
Excel=evalin('caller','Excel');
那么当我根据this文章添加以下几行时,
Excel = actxserver ('Excel.Application');
File='datafile.xls';
if ~exist(File,'file')
ExcelWorkbook = Excel.workbooks.Add;
ExcelWorkbook.SaveAs(File,1);
ExcelWorkbook.Close(false);
它给出了这个错误:
Error using xlswrite1 (line 82)
Range argument must a string of Excel A1 notation.
谁能提出一个简单的解决方案?到目前为止,我无法从我的在线搜索中找到任何内容。
【问题讨论】:
标签: matlab csv for-loop memory optimization