在MATLAB中删除结构中的字段

Dev*_*Dev 2 matlab

我的结构Vinlu大小为1X36:

        Vinlu = 

        vessel: [1x36 struct]
Run Code Online (Sandbox Code Playgroud)

每个都有5个字段:

Vinlu.vessel

        ans = 

        1x36 struct array with fields:
        pixels
        indexNOmask
        indexWHOLEvessel
        widths
        Meanwidth
Run Code Online (Sandbox Code Playgroud)

有一些容器字段,其中像素字段为空,例如:

Vinlu.vessel(1,4)

   ans = 

              pixels: [0x2 double]
         indexNOmask: [0x1 double]
    indexWHOLEvessel: [0x1 double]
              widths: [1x0 single]
           Meanwidth: NaN
Run Code Online (Sandbox Code Playgroud)

我想从像素字段为空的结构中删除所有那些容器字段(与其他字段无关).容器中的一个或多个字段可能是空的但我想删除那些具有空像素字段的字段,这样我将获得大小为1 X n的结构Vinlu,其中n <36

Eit*_*n T 7

首先找到vessel具有空pixels字段的结构的索引:

idx = cellfun('isempty', {Vinlu.vessel.pixels});
Run Code Online (Sandbox Code Playgroud)

然后只保留那些vessel具有非空pixels字段的元素:

Vinlu.vessel = Vinlu.vessel(~idx);
Run Code Online (Sandbox Code Playgroud)

在单行中看起来像这样:

Vinlu.vessel = Vinlu.vessel(~cellfun('isempty', {Vinlu.vessel.pixels}))
Run Code Online (Sandbox Code Playgroud)