Error using plot Vectors must be the same length

I'm getting the error "Error using plot Vectors must be the same length", however I can't quite figure out where the error is in using plot. I am attaching a photo of the code.

11 件のコメント

Mathieu NOE
Mathieu NOE 2023 年 5 月 4 日
hello
a photo of a code is not very helpful
better if you can share the code itself and data to test it
have you at least checked the size of the data you are plotting ?
Dyuman Joshi
Dyuman Joshi 2023 年 5 月 4 日
To add to Mathieu's comment, you are trying to plot n_for points in x vs (1 + n_for) points in y, which is not possible and thus you get the error.
Michal Kalowski
Michal Kalowski 2023 年 5 月 4 日
Attached is a code snippet and data for it, I still can't find the error. In x or y should I change the length of the vector?
Michal Kalowski
Michal Kalowski 2023 年 5 月 4 日
Attached is a code snippet and data for it, I still can't find the error. In x or y should I change the length of the vector?
Dyuman Joshi
Dyuman Joshi 2023 年 5 月 4 日
"In x or y should I change the length of the vector?"
Depends on what you want to do. What are you trying to plot? What is the expected output?
Michal Kalowski
Michal Kalowski 2023 年 5 月 4 日
Projected and actual values are to be plotted in one plot for 44 data points
Dyuman Joshi
Dyuman Joshi 2023 年 5 月 4 日
Is there any reason why you are concatenating x(end) with the data form yfor?
If it is important than you will have to adjust yfor, otherwise you can remove x(end) and plot against the data from yfor.
Michal Kalowski
Michal Kalowski 2023 年 5 月 4 日
I don't quite understand the answer, can you point me to the piece of code that I should change and what to change in it?
Dyuman Joshi
Dyuman Joshi 2023 年 5 月 4 日
編集済み: Dyuman Joshi 2023 年 5 月 4 日
Either try this -
plot(length(x)+(1:n_for), cell2mat(yfor), 'r')
or
plot(length(x)+(1:n_for), [x(end); cell2mat(yfor(1:end-1))], 'r')
Michal Kalowski
Michal Kalowski 2023 年 5 月 4 日
Ok super. Thank you for your help
Michal Kalowski
Michal Kalowski 2023 年 5 月 9 日
I have one more question, how to implement seasonal back differencing and first order back differencing into the sent code. I am attaching an example of such code that I would like to enter into my code.
dd = length(y_1d); kk = length(y);
for i =1:n_for
y_1d(dd+i) = yfor(i) + y_1d(dd-m+i); %seasonal back differencing
end
for i = 1:n_for
y(kk+i) = y(kk-1+i) + y_1d(dd+i); %first order back differencing
end

サインインしてコメントする。

回答 (0 件)

カテゴリ

製品

リリース

R2018b

質問済み:

2023 年 5 月 4 日

コメント済み:

2023 年 5 月 9 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by