matlab中predict函数用法

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了matlab中predict函数用法相关的知识,希望对你有一定的参考价值。

参考技术A clc,
clear
a=[
];
a=a';
a=a(:);
a=a';
%把原始数据按照时间顺序展开成一个行向量
Rt=tiedrank(a)
%求原始时间序列的秩
n=length(a);
t=1:n;
Qs=1-6/(n*(n^2-1))*sum((t-Rt).^2)
%计算Qs的值
t=Qs*sqrt(n-2)/sqrt(1-Qs^2)
%计算T统计量的值
t_0=tinv(0.975,n-2)
%计算上alpha/2分位数
b=diff(a)
%求原始时间序列的一阶差分
m=ar(b,2,'ls')
%利用最小二乘法估计模型的参数
bhat=predict(m,[b';
0],1)
%1步预测,样本数据必须为列向量,要预测1个值,b后要加1个任意数,1步预测数据使用到t-1步的数据
ahat=[a(1),a+bhat1']
%求原始数据的预测值,并计算t=15的预测值
delta=abs((ahat(1:end-1)-a)./a)
%计算原始数据预测的相对误差
Predict
函数为指定列返回一个或一组预测值。
  语法:
  Predict(<scalar
column
reference>,
[option1],
[option2],
[option
n],
[INCLUDE_NODE_ID],
n)
  Predict(<table
column
reference>,
[option1],
[option2],
[option
n],
[INCLUDE_NODE_ID],
n)
  适用范围:标量列引用或表列引用。
  返回类型:
  <scalar
column
reference>
  或者
  <table
column
reference>
  返回类型取决于应用此函数的列的类型。
  注释:
  选项包括
EXCLUDE_NULL(默认值)、INCLUDE_NULL、INCLUSIVE、EXCLUSIVE(默认值)、INPUT_ONLY

INCLUDE_STATISTICS。
  注意:对于时序模型,Predict
函数不支持
INCLUDE_STATISTICS。
  INCLUDE_NODE_ID
参数在结果中返回
$NODEID
列。
NODE_ID
是为特定事例而对其执行预测的内容节点。
对表列使用
Predict
时,此参数是可选的。
  n
参数适用于表列。
该参数根据预测类型设置返回的行数。
如果基础列是序列,则该参数将调用
PredictSequence
函数。
如果基础列是时序,则该参数将调用PredictTimeSeries
函数。
对于关联类型的预测,该参数将调用
PredictAssociation
函数。
  Predict
函数支持多态性。
  下面的替代缩写形式较为常用:
  [Gender]
用于替代
Predict([Gender],
EXCLUDE_NULL)。
  [Products
Purchases]
用于替代
Predict([Products
Purchases],
EXCLUDE_NULL,
EXCLUSIVE)。
  注意:此函数的返回类型本身被视为列引用。
也就是说,可将
Predict
函数用作以列引用作为参数的其他函数(Predict
函数本身除外)的参数。
  将
INCLUDE_STATISTICS
传递给对表值列的预测时,将在生成的表中添加
$Probability

$Support
列。
这些列说明了关联的嵌套表记录的存在概率。
  示例:
  SELECT
Predict([Association].[v
Assoc
Seq
Line
Items],INCLUDE_STATISTICS,4)
FROM
[Association]

急求matlab中predict函数的正确使用

希望达到的目的是根据时间序列数据中的值预测下一秒的数据
就不要复制粘贴了哈...网上有的我全看过一遍了...没有能解决问题的

参考技术A 这是matlab给的解释,你看吧

predict
Predict output k steps ahead
Syntax
yp = predict(m,data)
[yp,x0p,mpred] = predict(m,data,k,'InitialState',init)

Description

data is the output-input data as an iddata object, and m is any idmodel or idnlmodel object. predict is meaningful only for time-domain data.

The argument k indicates that the k step-ahead prediction of y according to the model m is computed. In the calculation of yp(t), the model can use outputs up to time

t–k: y(s), s = t–k, t–k–1,...

and inputs up to the current time t. The default value of k is 1.

The output yp is an iddata object containing the predicted values as OutputData.

x0p is the used (estimated) initial state vector. For multiexperiment data, x0p is a matrix, whose columns contain the initial states for each experiment.

The output argument mpred contains the k step-ahead predictor. This is given as a cell array, whose kth entry is an idpoly model for the predictor of output number k. Note that these predictor models have as input both input and output signals in the data set. The channel names indicate how the predictor model and the data fit together.

init determines how to deal with the initial state:

init ='e(stimate)': The initial state is set to a value that minimizes the norm of the prediction error associated with the model and the data.

init = 'd(elayexpand)': Same as 'estimate', but for a model with nonzero InputDelay, the delays are first converted to explicit model delays (using inpd2nk) so that they are contained in x0p.

init = 'z(ero)' sets the initial state to zero.

init = 'm(odel)' uses the model's internally stored initial state.

init = x0, where x0 is a column vector of appropriate dimension, uses that value as initial state. For multiexperiment data, x0 can be a matrix whose columns give different initial states for each experiment. For a continuous-time model m, x0 is the initial state for this model. Any modifications of the initial state that sampling might require are automatically handled. If m has a non-zero InputDelay, and you need to access the values of the inputs during this delay, you must first apply inpd2nk(m). When m is a continuous-time model, it must first be sampled before inpd2nk can be applied.

If init is not specified for linear models, its value is determined, as follows:

If m.InitialState is 'Estimate', 'Backcast', and 'Auto', init = 'Estimate'.

If m.InitialState is 'Zero', init = 'zero'.

If m.InitialState is 'Model' or 'Fixed', init = 'model'. For idss, idproc, and idgrey models, init corresponds to the m.x0 values. For other linear models, init = 'zero'.

If init is not specified for idnlgrey models, init = 'Model' is the default. The values and their estimation behavior are inherited from m.InitialStates.

If init is not specified for idnlarx models, init = 'Estimate' is the default. This corresponds to the first few samples of predicted outputs exactly matching the first few output samples in the data set.

If init is not specified for idnlhw models, init = 'Estimate' is the default. This computes initial states by minimizing the prediction errors over the available data range.

An important use of predict is to evaluate a model's properties in the mid-frequency range. Simulation with sim (which conceptually corresponds to k = inf) can lead to levels that drift apart, since the low-frequency behavior is emphasized. One step-ahead prediction is not a powerful test of the model's properties, since the high-frequency behavior is stressed. The trivial predictor can give good predictions in case the sampling of the data is fast.

Another important use of predict is to evaluate time-series models. The natural way of studying a time-series model's ability to reproduce observations is to compare its k step-ahead predictions with actual data.

Note that for output-error models, there is no difference between the k step-ahead predictions and the simulated output, since, by definition, output-error models only use past inputs to predict future outputs.
Algorithms

The model is evaluated in state-space form, and the state equations are simulated k steps ahead with initial value , where is the Kalman filter state estimate.
Examples

Simulate a time series, estimate a model based on the first half of the data, and evaluate the four step-ahead predictions on the second half.
m0 = idpoly([1 -0.99],[],[1 -1 0.2]);
e = iddata([],randn(400,1));
y = sim(m0,e);
m = armax(y(1:200),[1 2]);
yp = predict(m,y,4);
plot(y(201:400),yp(201:400))

Note that the last two commands are also achieved by
compare(y,m,4,201:400);

See Also

compare | pe | sim | sims

clc, clear

a=[ ];
a=a'; a=a(:); a=a'; %把原始数据按照时间顺序展开成一个行向量
Rt=tiedrank(a) %求原始时间序列的秩
n=length(a); t=1:n;
Qs=1-6/(n*(n^2-1))*sum((t-Rt).^2) %计算Qs的值
t=Qs*sqrt(n-2)/sqrt(1-Qs^2) %计算T统计量的值
t_0=tinv(0.975,n-2) %计算上alpha/2分位数
b=diff(a) %求原始时间序列的一阶差分
m=ar(b,2,'ls') %利用最小二乘法估计模型的参数
bhat=predict(m,[b'; 0],1) %1步预测,样本数据必须为列向量,要预测1个值,b后要加1个任意数,1步预测数据使用到t-1步的数据
ahat=[a(1),a+bhat1'] %求原始数据的预测值,并计算t=15的预测值
delta=abs((ahat(1:end-1)-a)./a) %计算原始数据预测的相对误差追问

一开始就看过了。。按他说的做结果有些问题。。。您能不能自己写个实际的程序呢

本回答被提问者采纳

以上是关于matlab中predict函数用法的主要内容,如果未能解决你的问题,请参考以下文章

MATLAB中plot函数用法

Delphi 中PChar()函数的用法

matlab movie函数的用法

matlab中某些函数的用法

matlab 中 bwboundaries 函数 的用法

matlab中hough函数用法