フィルターのクリア

Can you check my error code?

1 回表示 (過去 30 日間)
SEANGHAI THA
SEANGHAI THA 2019 年 12 月 6 日
コメント済み: Ridwan Alam 2019 年 12 月 6 日
Hello! Can you correct my code? Because I have some errors on my code.
%% Starting codes
x = linspace (-2,4,101);
span = [0 1 2];
for i = -1: 2
h1 = plot (x (x> (span (1) + i * 2) & x <(span (2) + i * 2)), ...
zeros (size (x (x> (span (1) + i * 2) & x <(span (2) + i * 2)))));
hold on;
h2 = plot (x (x> (span (2) + i * 2) & x <(span (3) + i * 2)), ...
ones (size (x (x> (span (2) + i * 2) & x <(span (3) + i * 2)))));
set (h1, 'linewidth', 3, 'color', 'b');
set (h2, 'linewidth', 3, 'color', 'b');
end
ylim ([-1 2]);
grid on;
title ('f (x) vs Fourier Series', 'front size', 16);
n = 0: 100;
for i = 1: length (x)
f (i) = 0.5-sum (2 / pi. * sin ((2 * n + 1) * pi * x (i)) ./ (2 * n + 1));
set (f (i), 'linewidth', 3, 'color', 'b');
end
plot (x, f, 'r');
hold off
And I got errors like the following:

回答 (1 件)

Ridwan Alam
Ridwan Alam 2019 年 12 月 6 日
編集済み: Ridwan Alam 2019 年 12 月 6 日
x = linspace (-2,4,101);
span = [0 1 2];
for i = -1: 2
h1 = plot (x (x> (span (1) + i * 2) & x <(span (2) + i * 2)), ...
zeros (size (x (x> (span (1) + i * 2) & x <(span (2) + i * 2)))));
hold on;
h2 = plot (x (x> (span (2) + i * 2) & x <(span (3) + i * 2)), ...
ones (size (x (x> (span (2) + i * 2) & x <(span (3) + i * 2)))));
set (h1, 'linewidth', 3, 'color', 'b');
set (h2, 'linewidth', 3, 'color', 'b');
end
ylim ([-1 2]);
grid on;
title ('f (x) vs Fourier Series', 'FontSize', 16); % not 'front size'
n = 0: 100;
for i = 1: length (x)
f (i) = 0.5-sum (2 / pi. * sin ((2 * n + 1) * pi * x (i)) ./ (2 * n + 1));
set (f (i), 'linewidth', 3, 'color', 'b');
end
plot (x, f, 'r');hold off;
  2 件のコメント
SEANGHAI THA
SEANGHAI THA 2019 年 12 月 6 日
Oh! Many thank for your help!
Ridwan Alam
Ridwan Alam 2019 年 12 月 6 日
Sure. Glad to help. Please accept the response as an answer.

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

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by