MATLAB代码画图仿真,
运行错误,想请大家帮忙看一下。提示这个东西不能这样索引
运行代码会报错,提示“这个东西不能这样索引”。问题出在第7行,尝试将hL(2)
改为hL(1)
即可解决问题。修改后的代码如下:
x = linspace(0,10*pi,200);
y = sin(x);
figure;
hL = plot(x, y);
hold on;
hL(1) = plot(x, exp(-0.1*x).*sin(x));
hL(2) = plot(x, cos(x).*sin(x));
hL(3) = plot(x, exp(-0.1*x).*cos(x).*sin(x));
set(hL(1), 'LineWidth', 2)
set(hL(2), 'LineStyle', '--', 'LineWidth', 2)
set(hL(3), 'LineWidth', 2, 'Color', [0.5 0.5 0.5], 'LineStyle', '--')
xlabel('x')
ylabel('y')
title('Matlab Plot Demo')
legend(hL, 'y = sin(x)', 'y = e^{-0.1x}sin(x)', 'y = cos(x)sin(x)', 'y = e^{-0.1x}cos(x)sin(x)');