我有一个外部函数,在模拟过程中最多需要调用两次。它具有较大的输出大小Real[n][m][k],其中 n、m 和 ks 的乘积是一个相对较大的整数。我在when语句中调用该函数。我遇到的问题是,每次迭代都会在 .mat 文件中一遍又一遍地复制函数的输出,并导致它非常大,即使我很少使用输出。我想知道是否有一种方法只存储输出一次,并避免在每个时间步将输出的副本存储在结果文件中。
Ps 如果这是不可能的,我可能会尝试将函数的结果存储在另一个文件中,但需要在模拟中使用它们。因此,作为替代方案,还有一种方法可以使模拟忽略在结果文件中存储变量。
我想用 C++ 编写一个通用函数来展平所提供的任何多维向量。该方法的签名如下:
template <class U, class T>
void flatten(U* out, T& inp, int* dims, int n){
// out is the flattened output
// inp is some multidimensional vector<vector...<U>>
// dims is an array of the dimensions of inp
// n is the number of dimensions of inp
int ticker[n];
int prodLimit = 1;
int prod = 0;
// calculate prodLimit as product of elements in dims and initialize ticker
for (int i=0; i<n; i++){
ticker[i] = 0;
prodLimit *= …Run Code Online (Sandbox Code Playgroud)