Is there a way to optimize this code?
显示 更早的评论
fout = fopen(binFileName, 'w');
for r = 1:size(data{1, 1}.X, 1)
for c = 1:size(data{1, 1}.X, 2)
fwrite(fout, data{1, 1}.X(r, c), 'float');
end
end
fclose(fout);
回答(1 个)
fout = fopen(binFileName, 'w');
if fout == -1
error('Cannot open file fro writing: %s', binFileName);
end
fwrite(fout, data{1}.X.', 'float');
fclose(fout);
This could be slightly faster with fopen('W') (upper-case). But even then the hard disk will be the bottleneck.
3 个评论
Luigi Bianchi
2018-3-28
编辑:Walter Roberson
2018-3-28
Walter Roberson
2018-3-28
data{1} and data{1,1} are the same location. data{1} is linear indexing form, and is always equivalent to data{1,1}.
Luigi Bianchi
2018-3-28
类别
在 帮助中心 和 File Exchange 中查找有关 Get Started with Optimization Toolbox 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!