Matlab:可以在另一个文件中放置大量的预分配吗? [英] Matlab: Can a large number of preallocations be placed in another file?
本文介绍了Matlab:可以在另一个文件中放置大量的预分配吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在研究一个Matlab代码,其中有很多需要预先分配的变量(每个变量为8760x1 double).这些值在for循环中生成:
a=zeros(8760,1);
b=zeros(8760,1);
(...)
for i=1:8760
a(i)=[some code];
b(i)=[some code];
(...)
end
但是,看到我有很多这样的变量,我想在另一个文件中预分配参数(更干净).
preallocate.m
a=zeros(8760,1);
b=zeros(8760,1);
...
main.m
preallocate
for i=1:8760
a(i)=[some code];
b(i)=[some code];
(...)
end
在另一个matlab文件中进行预分配是否会与在与执行文件相同的文件中进行预分配一样有效?还有其他建议吗?
解决方案
是的.
I'm working on a matlab code where I have a lot of variables that need to be preallocated (each variable is 8760x1 double). The values are generated in a for loop:
a=zeros(8760,1);
b=zeros(8760,1);
(...)
for i=1:8760
a(i)=[some code];
b(i)=[some code];
(...)
end
However, seeing that I have a lot of these variables, I want to preallocate the parameters in another file (more clean).
preallocate.m
a=zeros(8760,1);
b=zeros(8760,1);
...
main.m
preallocate
for i=1:8760
a(i)=[some code];
b(i)=[some code];
(...)
end
Will preallocating in another matlab file be as efficient as doing it in the same file as the executing file? Other suggestions?
解决方案
Yes.
这篇关于Matlab:可以在另一个文件中放置大量的预分配吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文