我有一段代码,它基本上选择一些数据段并对这些数据段执行一些计算(回归线,所以我看一下延伸线的斜率和截距)。代码工作正常,最后它在Command窗口中显示所有循环迭代的结果,但它只能在最后一个循环迭代结果的矩阵(称为final)中出现。基本上我想将所有结果都放在矩阵中。将所有迭代循环结果存储在矩阵中
在这里,我附上代码:
Data = csvread(inputFile);
for i=1:max(L)
try
B = [ones(length(result{i}),1) result{i}(:,1)] \ result{i}(:,2);
catch
continue
end
intercept = B(1);
slope = B(2);
position = (slope.*result{i}(end,1)+intercept)-(slope .*result{i}(1:1)+intercept);
time = result{i}(end,1)-result{i}(1:1);
final =[slope, intercept, position, time]
end
目前我得到的命令窗口中的每个循环的结果。所以我得到这样的事情:
final =
4.6607 -27.7973 0.0621 0.0133
final =
-0.0647 -0.1299 -0.0517 0.7992
final =
-9.0676 74.6981 -0.0604 0.0067
final =
0.3176 -3.2234 0.0698 0.2198
final =
0.2153 -2.3666 0.0631 0.2930
final =
-5.1864 45.6418 -0.2072 0.0400
final =
-1.0881 9.1772 -0.0797 0.0733
final =
-0.5416 4.3386 -0.1605 0.2964
final =
-4.4898 39.8786 -1.2409 0.2764
final =
-3.0985 26.3052 -0.0619 0.0200
final =
2.0871 -24.2849 0.0208 0.0100
final =
1.0060 -15.6203 0.0067 0.0067
我怎样才能得到所有这一切矩阵?
在此先感谢!
当显示大量MATLAB命令窗口输出的,最好是用'格式compact':HTTP:// www.mathworks.com/help/matlab/ref/format.html#inputarg_Style – chappjc