Octave 如何在倍频程中索引单元格数组类属性?

Octave 如何在倍频程中索引单元格数组类属性?,octave,Octave,我有一个单元格数组类属性: classdef imageSet properties (SetAccess='protected', GetAccess='public') ImageLocation = {''}; % Image locations end ... 我想通过如下索引方式访问它: imgSet.ImageLocation{3} 但我收到一条错误消息:无法对imageSet对象数组执行索引操作 然而 a = imgSet.ImageLocati

我有一个单元格数组类属性:

classdef imageSet
    properties (SetAccess='protected', GetAccess='public')
        ImageLocation = {''}; % Image locations
    end
...
我想通过如下索引方式访问它:

imgSet.ImageLocation{3}
但我收到一条错误消息:无法对imageSet对象数组执行索引操作

然而

a = imgSet.ImageLocation
a{3}

很好。为什么,我如何修复它?

您必须有一个
图像集
对象数组。你可以跟我核对一下

size(imgSet)    % Will be something other than [1, 1] (a scalar)
a=imgSet.ImageLocation
起作用的原因是
imgSet.ImageLocation
创建了一个逗号分隔的列表,并且只有第一个
imgSet
对象被分配给
a
。然后,第一个对象是标量
imageSet
对象,因此您可以索引到
ImageLocation
属性而不会出现问题

这可以通过以下方式演示

% Create an array of structs
a = struct('one', {1, 2, 3}, 'two', {4, 5, 6})

% Create a comma-separated list from the one field
b = a.one;

% See that only the element was used (a(1).one)
disp(b)
%   1
因为它是一个数组,所以在索引之前需要访问特定的
imgSet
对象

imgSet(1).ImageLocation{3};

实际大小(imgSet)为[1]。@Balint请提供代码以复制整个问题。错误清楚地表明您有一个数组。我不知道它为什么会有其他想法。不管怎样,执行
imgSet(1).ImageLocation{3}
应该是可行的。我认为问题出在其他地方。如果你有matlab:这是imageSet.m<代码>a=imageSet('path/to/images/folder');a、 ImageLocation{3}%工作正常b=select(a,1:4);b、 ImageLocation{3}%无法对imageSet对象数组执行索引操作
以下是代码的相关部分: