简体   繁体   English

在make fxn中将datajoint键设置为不同的变量

[英]Setting datajoint key to a different variable in make fxn

Wondering why and when it's needed to set the key to a different variable in a make/maketuples function in an auto-populated table in datajoint, as in the documentation here .想知道为什么以及何时需要在 datajoint 的自动填充表中将密钥设置为 make/maketuples function 中的不同变量,如此处的文档中所示

In this example, the part table SegmentationROI is defined as follows:在本例中,零件表 SegmentationROI 定义如下:

%{
# Region of interest resulting from segmentation
-> test.Segmentation
roi  : smallint   # roi number
---
roi_pixels  : longblob   #  indices of pixels
roi_weights : longblob   #  weights of pixels
%}

classdef SegmentationROI < dj.Part
    properties(SetAccess=protected)
        master = test.Segmentation
    end
    methods
        function make(self, key)
            image = fetch1(test.Image & key, 'image');
            [roi_pixels, roi_weighs] = mylib.segment(image);
            for roi=1:length(roi_pixels)
                entity = key;
                entity.roi_pixels = roi_pixels{roi};
                entity.roi_weights = roi_weights{roi};
                self.insert(entity)
            end
        end
    end
end

What is the purpose of renaming the key as a separate variable, entity (entity = key), and then inserting that?将键重命名为单独的变量实体(实体 = 键)然后插入它的目的是什么?

In this case, we're adding fields to entity as a struct.在这种情况下,我们将字段作为结构添加到entity I'd consider it best practice to preserve arguments a function as-is.我认为最好的做法是按原样保留 arguments 和 function。 If we added a second for-loop here, we might run into issues when calling key for another purpose.如果我们在这里添加第二个 for 循环,我们可能会在为其他目的调用key时遇到问题。

Caveat: I'm more familiar with DataJoint python and have not used it extensively in MATLAB.警告:我更熟悉 DataJoint python 并且没有在 MATLAB 中广泛使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM