Error using plot Vectors must be the same length

1 回表示 (過去 30 日間)
Madiha Jamil
Madiha Jamil 2019 年 11 月 24 日
回答済み: Star Strider 2019 年 11 月 24 日
I want to correlate the signals x1 and y and plot it for the range n=0:59; but when I run the following code it gives error: Error using plot
Vectors must be the same length.
n=0:59;
x=[1 1 1 1 1 -1 -1 1 1 -1 1 -1 1 ];
x=[x, zeros(1, length(n) - length(x))];
x1=x.^n;
subplot 221
stem(n,x1)
n1=20:79;
x2=0.9*(x1.^n1);
y=imnoise(x2,'gaussian');
subplot 222
stem(n,y)
z=xcorr(x1,y);
subplot 223
stem(n,z)
I have tried solving the problem but had no luck whatsoever. Any help would be appreciated.

回答 (1 件)

Star Strider
Star Strider 2019 年 11 月 24 日
One option is to plot ‘z’ as a function of the lags xcorr computes:
[z,lags] = xcorr(x1,y);
subplot 223
stem(lags,z)

カテゴリ

Help Center および File ExchangeCorrelation and Convolution についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by