【发布时间】:2021-06-01 00:18:13
【问题描述】:
Matlab 中的哪些时间和内存效率更高?
我正在编写伪代码。
1)
for:
Open a file
Read the temperature info
find the min max and avg temperature value;
for:
Open a file
Read the voltage info
find the min max and avg voltage value;
for:
Open a file
Read the resistence info
find the min max and avg resistence value;
或者下面的代码?
2)
for:
Open a file
Read the temperature info
find the min max and avg temperature value
Open a file
Read the voltage info
find the min max and avg voltage value
Open a file
Read the resistence info
find the min max and avg resistence value;
【问题讨论】:
-
这无法回答,唯一能确定需要更少时间的方法是实现两者并进行比较。但很可能“打开文件”和“从文件读取”是这里更昂贵的操作。循环本身并不昂贵,但是你在里面做的事情会重复很多次,这就是人们说循环很昂贵的原因。
-
您真的在单独的小文件中拥有所有这些信息吗?还是您多次打开和读取同一个文件?
标签: matlab for-loop memory time memory-management