Matkal运行错误

img


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)');

1、检查simout相关程序代码没有拼错
2、检查simout双击后属性页面save format为structure with time
3、检查工作区中ans是否包含simout这一结果
4、在程序中sim( )代码后加上simout = ans.simout;