我有一段代碼,它基本上選擇一些數據段並對這些數據段執行一些計算(迴歸線,所以我看一下延伸線的斜率和截距)。代碼工作正常,最後它在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