Plotting and Vectors Length Regularization

Hi,
I want to plot Out (length 777) and time (length 389) and error appears 'Vector must be of same length'. So I need to regularize time (want make time of same length of Out). How can I regularize time in MATLAB to get vector (time) af same length.

回答 (1 件)

madhan ravi
madhan ravi 2020 年 9 月 15 日

0 投票

plot(linspace(min(time), max(time), numel(Out)), Out)

3 件のコメント

Nisar Ahmed
Nisar Ahmed 2020 年 9 月 15 日
Thank you Madhan
I will try it, but intial values (first 12 values) of time are NaN, do I need fix it first are not?
Nisar Ahmed
Nisar Ahmed 2020 年 9 月 15 日
When I try this code plot(linspace(min(time), max(time), numel(Out)), Out)
same error appears. Vectors must be of same length.
Vinicius Pereira Mateus Borges
Vinicius Pereira Mateus Borges 2020 年 9 月 15 日
Indeed, if the first 12 elements are NaNs, the min(time) part of Madhan's code will not return 1, but rather 13 as an output. Then the variables still have different sizes.
You can solve this with the size function instead.
out = randn(1,777); %e.g. data
time = 1:389;
plot( linspace(size(time,1), size(time,2), length(out) ), out)

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

質問済み:

2020 年 9 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by