Vectors must be the same length

N1=64;
Y1=fft(y,N1);
x= (0:29);
subplot(3,1,2)
plot(x,abs(Y1))
xlabel('Frequency (Hz)');
ylabel('Amplitude');
%HOW TO MAKE IT SAME LENGTH?(LINE5)

 採用された回答

Star Strider
Star Strider 2021 年 11 月 27 日

0 投票

The number of elements in ‘Y1’ in the plot need to be the same as the number in ‘x’ so one way would be to re-define ‘x’ to be the desired length with respect to ‘Y1’ and another would be:
plot(x,abs(Y1(1:numel(x))))
Use the approach that gives the desired result.
.

5 件のコメント

Mya
Mya 2021 年 11 月 27 日
% I dun understand...if i add nume1.....the MATLAB won't recognize it
Mya
Mya 2021 年 11 月 27 日
so how to make Y1 same as x?
Star Strider
Star Strider 2021 年 11 月 27 日
It is not necessary toi make the entire vector the same size, only the range desired in the plot. That is what the code I posted does.
To make ‘x’ the same size as ‘Y1’ create it as:
x = linspace(0, numel(Y1), numel(Y1));
The length of ‘Y1’ is fixed by ‘N’ and since that governs everythin else, it creates another option:
x = 0:N-1;
Choose the one that gives the desired result.
.
Mya
Mya 2021 年 11 月 27 日
ok tq for ur guide
Star Strider
Star Strider 2021 年 11 月 27 日
As always, my pleasure!
.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMixed-Signal Blockset についてさらに検索

製品

タグ

質問済み:

Mya
2021 年 11 月 27 日

コメント済み:

2021 年 11 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by