Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设我想在中实现以下while-loop内容matlab:
while-loop
matlab
n=10; k=0; while k<n a = 3; Cnew = Ck "union" a; if (Ck+1==0) Ck+1 = Cnew; end end
我该怎么做,尤其是索引vectors?如何在 matlab 中拥有以下向量 C1、C2、C3、...等?
vectors
谢谢。
似乎您并不想生成不同的变量名称,例如c1, c2, ... 等。
c1
c2
您是否考虑过使用元胞数组?
你的代码看起来像
n=10; k=1; C{1} = []; while k <= n a = 3; Cnew = [ C{k}, a ]; if numel(C) < k+1 || isempty( C{k+1} ) % what you meant by Ck+1==0 ? C{k+1} = Cnew; end end
有关类似问题,请参阅此问题。