Matlab:如何动态更新for循环的限制?

Matlab:如何动态更新for循环的限制?,matlab,for-loop,limit,updates,Matlab,For Loop,Limit,Updates,我正在matlab中编写以下代码: m=unique(x); for i=1:length(m) %some code that increase the number of unique values in x ....... ....... %here I tried to update m m=unique(x); end 虽然我已经通过写这一行来更新了m,m=unique(x)在for结束之前,for循环的限制仍然具有相同的旧值。我需要动态更新for循环的限制。可能吗?如果可能的话,

我正在matlab中编写以下代码:

m=unique(x);
for i=1:length(m)
%some code that increase the number of unique values in x
.......
.......
%here I tried to update m 
m=unique(x);
end

虽然我已经通过写这一行来更新了
m
m=unique(x)在for结束之前,for循环的限制仍然具有相同的旧值。我需要动态更新for循环的限制。可能吗?如果可能的话,怎么做?

当MATLAB遇到i=1:length(m)的
时,它将语句转换为i=[1 2 3…length(m)]的
。你可以认为它是硬编码的。因此,for循环内的update for limit没有效果

m = unique(x);
i = 1;
while true
    if i > length(m)
        break
    end
    % do something
    i = i + 1;
    m = unique(x);
end

或者,简单一点:
m=unique(x);ii=0;虽然ii@LuisMendo在我看来,你的答案要好得多,可惜这只是一个评论。