不同的迭代输出

我在matlab中有这个
A=34;
for i =1:1:6
    A = A + 1;
t1=fix(A/(2*32));
t2=fix((A-(t1*64))/(32));
t3=fix(((A-(t1*64)) - (t2*32))/(16));
G = [t1 t2 t3]
end
当它显示时,它给出了
G= 0 1 0
G= 0 1 0
G= 0 1 0 ....to the 6th G(the values are not right anyway)
but I want to have an output of
G1= 0 1 0
G2= 0 1 0
G3= 0 1 0....to G6 
然后cat.or将它们放入一组G = [G1,G2,G3,...,G6]。请问如何完成这项工作?     
已邀请:
关于你的问题,有几点需要解决...... 预分配数组和矩阵索引: 如果要保存在每次迭代时生成的值,可以在循环之前将数组
G
预先分配为6乘3的零矩阵,然后在循环中索引到矩阵的给定行以存储值:
A = 34;
G = zeros(6, 3);  % Make G a 6-by-3 matrix of zeroes
for i = 1:6
  % Your calculations for t1, t2, and t3...
  G(i, :) = [t1 t2 t3];  % Add the three values to row i
end
矢量化操作: 在许多情况下,您可以在MATLAB中完全避免循环,并且通常使用向量化操作来加速代码。在您的情况下,您可以为
A
创建值向量,并使用算术数组运算符
.*
./
在元素方面执行
t1
t2
t3
的计算:
>> A = (35:40).';   %' Create a column vector with the numbers 35 through 40
>> t1 = fix(A./64);  % Compute t1 for values in A
>> t2 = fix((A-t1.*64)./32);         % Compute t2 for values in A and t1
>> t3 = fix((A-t1.*64-t2.*32)./16);  % Compute t3 for values in A, t1, and t2
>> G = [t1 t2 t3]  % Concatenate t1, t2, and t3 and display

G =

     0     1     0
     0     1     0
     0     1     0
     0     1     0
     0     1     0
     0     1     0
这里的奖励是
G
将自动结束为包含您想要的所有值的6乘3矩阵,因此不需要预分配或索引。 显示输出: 如果要创建格式化输出,该输出不同于在行尾省略分号时出现的默认数字显示,则可以使用类似
fprintf
的函数。例如,要获得您想要的输出,您可以在创建
G
之后运行它,如上所述:
>> fprintf('G%d = %d %d %dn', [1:6; G.'])  %' Values are drawn column-wise
G1 = 0 1 0                                   %   from the second argument
G2 = 0 1 0
G3 = 0 1 0
G4 = 0 1 0
G5 = 0 1 0
G6 = 0 1 0
    
如果我理解正确你的问题只是输出(所有值都存储在G中),对吧? 你可以试试这个:
lowerbound = (i-1)*3 + 1;
G(lowerbound:lowerbound + 2) = [t1 t2 t3]
这应该使用新计算的值扩展G.     

要回复问题请先登录注册