我一直在做数组索引如下MATLAB数组索引错误?
>> n=[1 2 3]
n =
1 2 3
>> idx=1
idx =
1
>> n([idx+1 idx])
ans =
2 1
没有任何问题。但是,今天我在我的下面的代码片段中遇到了这个错误。请原谅我。我明白我应该提供MWE,但我根本无法重现错误!
>> %%% interpret tree
bitmap = zeros(pix_no_per_side, pix_no_per_side);
x_pixels = 1:1:pix_no_per_side;
y_pixels = 1:1:pix_no_per_side;
rule_set = {}; % cell to accommodate rows of diff. sizes
% parse branches
trav_iter = tr.depthfirstiterator;
while tr.get(trav_iter(end)) <= 0 % still have branch unparsed
branch = [1]; % contains the root
node_idx = 1;
while tr.get(branch(end)) > 0 % not bottom yet
node_idx = node_idx+1;
branch = [branch trav_iter(node_idx)];
end
rule_set{end+1} = branch; % one rule per cell
disp(node_idx) % DISPLAYING FOR DEBUGGING
if numel(rule_set) == 1 % only one branch found so far
trav_iter(node_idx) = []; % remove this leaf
else % more than one branches found so far
trav_iter([node_idx-1 node_idx]) = []; % remove this leaf and parent node
end
end
3
3
2
Subscript indices must either be real positive integers or logicals.
>>
谢谢,但'3 3 2'是我在执行'disp(node_idx)'时得到的结果。 –