Error using stem X must be same length as Y.

5 ビュー (過去 30 日間)
Geovani
Geovani 2023 年 12 月 11 日
回答済み: Dyuman Joshi 2023 年 12 月 11 日
% Given sequences x[n] and y[n]
n_values = 0:10;
x_values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
y_values = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1];
% Evaluate the expression 2x[n-1] + y[n+2]
expression_result = 2 * circshift(x_values, [0, -1]) + circshift(y_values, [0, 2]);
% Plot the result
stem(n_values, expression_result, 'b', 'LineWidth', 2);
% Customize the plot
xlabel('n');
ylabel('2x[n-1] + y[n+2]');
title('Sequence 2x[n-1] + y[n+2]');
grid on;
% Adjust the axis limits for better visualization
axis([min(n_values)-1, max(n_values)+1, min(expression_result)-1, max(expression_result)+1]);

回答 (1 件)

Dyuman Joshi
Dyuman Joshi 2023 年 12 月 11 日
The variable n_values has 11 elements, compared 10 elements for x_values, y_values, and expression_result (which is the result of combination of the first 2)
You should modify the variable n_values accordingly, with possible values being 0:9 and 1:10.

カテゴリ

Help Center および File ExchangeDiscrete Data Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by