指针在MATLAB中的建议 [英] advice with pointers in matlab

查看:86
本文介绍了指针在MATLAB中的建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一个非常大的元模拟,在该模拟中,我将经历两个超参数(分别说x和y),并且对于每组超参数(x_i和y_j),我都会进行一个中等大小的子模拟.因此:

I am running a very large meta-simulation where I go through two hyperparameters (lets say x and y) and for each set of hyperparameters (x_i & y_j) I run a modest sized subsimulation. Thus:

for x=1:I
    for y=1:j
        subsimulation(x,y)
    end
end

但是,对于每个子模拟,大约50%的数据对于其他每个子模拟或子模拟(x_1,y_1).commondata = subsimulation(x_2,y_2).commondata是公用的.

For each subsimulation however, about 50% of the data is common to every other subsimulation, or subsimulation(x_1,y_1).commondata=subsimulation(x_2,y_2).commondata.

这非常重要,因为到目前为止,模拟结果文件的总大小约为10Gb!显然,我想将公共子仿真数据保存1次以节省空间.但是,将其保存在一个地方的明显解决方案会搞砸我的绘图功能,因为它直接调用subsimulation(x,y).commondata.

This is very relevant since so far the total simulation results file size is ~10Gb! Obviously, I want to save the common subsimulation data 1 time to save space. However, the obvious solution, being to save it in one place would screw up my plotting function, since it directly calls subsimulation(x,y).commondata.

我想知道我是否可以做类似的事情 subsimulation(x,y).commondata =%指向内存%1中位置的指针

I was wondering whether I could do something like subsimulation(x,y).commondata=% pointer to 1 location in memory %

如果那行不通,那么这种不太优雅的解决方案呢?

If that cant work, what about this less elegant solution:

subsimulation(x,y).commondata='variable name' %string

然后添加

if(~isstruct(subsimulation(x,y).commondata)), 
    subsimulation(x,y).commondata=eval(subsimulation(x,y).commondata)
end

你们认为哪种解决方案是最好的?

What solution do you guys think is best?

谢谢 DankMasterDan

Thanks DankMasterDan

推荐答案

您可以通过定义文档.

You could do this fairly easily by defining a handle class. See also the documentation.

一个例子:

classdef SimulationCommonData < handle
    properties
        someData
    end

    methods
        function this = SimulationCommonData(someData)
            % Constructor
            this.someData = someData;
        end
    end
end

然后像这样使用

commonData = SimulationCommonData(something);
subsimulation(x, y).commondata = commonData;
subsimulation(x, y+1).commondata = commonData; 
% These now point to the same reference (handle)

这篇关于指针在MATLAB中的建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆