Matlab 编码器错误 "for loop index expressions.." 如何修改代码?

Matlab coder error "for loop index expressions.." how to modify code?

本文关键字:修改 代码 何修改 expressions 错误 编码器 for loop Matlab index      更新时间:2023-10-16

在 Matlab 编码器上,每当我用于索引 for 循环中的向量时,我都会收到错误"未知大小的 FOR 循环索引表达式仅在形式为 A:B 或 A:B:C 时受支持",例如:

for e=s:-1:1
for l=1:s
    for k=1:b       
    E=find(sum(B(:,l,:))==k)';
    coder.varsize('E', [1,70],[0,1]);
        for j=E
            coder.varsize('i', [1,70],[0,1]);
            for i=E
                if isequal(B(:,e,i),B(:,e,j)) %for k=1 we want the second column of i to be identical to the first colum of j or vice versa. 
                    if isequal(sort(sum(B(1:s,s+1:b+s,i))),sort(sum(B(1:s,s+1:b+s,j))))
                        B(:,l,i)=B(:,l,j);
                        B(l,:,i)=B(l,:,j);
                    else
                        ;
                    end
                end
            end
        end
    end
end
end

我知道编码人员需要类似"A:B"的东西,但我的向量 E 在这里包含例如 [7,11,13],我不能使用类似"E(1,1):E(1,3)"的东西,因为那样我就会得到 7 8 9 10 11 12 13。

关于如何修改代码的任何建议?

谢谢

为什么不简单地做:

for ind = 1:length(E)
    i = E(ind);
    % ...
end