移動平均法是運用過去時間序列的資料進行統計分析去推測事物的發展趨勢,适用于曆史序列的基本趨勢變化不大且序列中随機變動成分較多時使用,隻适合做近期預測。之前介紹了基于MATLAB的guide制作的一次移動平均法計算的GUI界面,但是随着MATLAB版本的更新,之後的版本不再支援guide制作的GUI界面,是以我基于MATLAB App Designer将一次移動平均法模型修改成App,這樣可以相容2016之後的版本,也不受最新版本的限制。
基于MATLAB的一次移動平均法預測App如下:
加載資料——輸入原始資料起始年份、原始資料最終年份、步長數、預測資料個數、x軸坐标名稱、y軸坐标名稱——點選開始計算即可出現結果,同時會在目前檔案夾下生成預測資料的excel檔案“MSE.xlsx”,“結果.xlsx”和預測結果圖的bmp、fig、jpg和pdf格式檔案。需要基于MATLAB的一次移動平均法預測App完整程式,可以進行打賞後截圖(30元及以上),在微信公衆号雲龍派裡電競迷“聯系掌門”菜單進行聯系,或者在公衆号内回複截圖,幾小時内會回複。App Designer程式設計不易,還請見諒!
1.基于MATLAB的一次移動平均法預測App舉例計算
資料為内蒙古2009-2017年貨品運輸數量,利用一次移動平均法向後預測3年。
Step1:點選yiciyidongApp.mlappinstall檔案,在MATLAB中輕按兩下安裝APP,點選安裝到我的APP。
Step2:在APP 菜單欄中找到我的app中的yiciyidongApp,輕按兩下運作出App主界面。
Step3:點選加載資料,選擇資料excel檔案,并點選确定。
Step4:輸入參數。
Step5:點選開始計算。
Step6:運作結果檔案生成。
2.App主要程式如下
classdef yiciyidongapp < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
Panel matlab.ui.container.Panel
Panel_2 matlab.ui.container.Panel
Button matlab.ui.control.Button
Label_3 matlab.ui.control.Label
EditField matlab.ui.control.NumericEditField
Label_4 matlab.ui.control.Label
EditField_2 matlab.ui.control.NumericEditField
Label_5 matlab.ui.control.Label
EditField_3 matlab.ui.control.NumericEditField
xEditFieldLabel matlab.ui.control.Label
xEditField matlab.ui.control.EditField
yEditFieldLabel matlab.ui.control.Label
yEditField matlab.ui.control.EditField
EditField_4Label matlab.ui.control.Label
EditField_4 matlab.ui.control.EditField
Panel_3 matlab.ui.container.Panel
Button_2 matlab.ui.control.Button
Button_3 matlab.ui.control.Button
Button_4 matlab.ui.control.Button
Panel_4 matlab.ui.container.Panel
UIAxes matlab.ui.control.UIAxes
TextArea matlab.ui.control.TextArea
UITable matlab.ui.control.Table
Label matlab.ui.control.Label
UITable_2 matlab.ui.control.Table
Label_2 matlab.ui.control.Label
end
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: Button_3
function Button_3Pushed(app, event)
app.EditField.Value = 0;
app.EditField_2.Value = 0;
app.EditField_3.Value = 0;
app.EditField_4.Value = " ";
app.xEditField.Value = " ";
app.yEditField.Value = " ";
app.UITable.Data = [];%矩陣資料使表格為空
app.UITable_2.Data = [];
try
delete(allchild(app.UIAxes));
end
end
% Button pushed function: Button_4
function Button_4Pushed(app, event)
closereq;
end
% Button pushed function: Button
function ButtonPushed(app, event)
%加載資料 使用全局變量傳遞加載的資料
global data12
[filename,pathname,filterindex]=uigetfile({'*.xlsx';'*.txt';'*.*'},'打開資料');
if ~filename
return;
end
str1=[pathname,filename];
if (filename==0 & pathname==0)
msgbox('您沒有選擇檔案,請重新選擇!','打開檔案出錯','error');
else
% data=xlsread (strcat([pathname filename])); %strcat是組成路徑的。
data12 = xlsread (strcat([pathname filename]));
msgbox('打開及讀取資料完畢!','确認','warn');
end
end
本文内容來源于網絡,僅供參考學習,如内容、圖檔有任何版權問題,請聯系處理,24小時内删除。
作 者 | 郭志龍
編 輯 | 郭志龍
校 對 | 郭志龍