MATLAB绘制多条函数曲线

发布时间 2023-08-31 14:35:22作者: 代码搬运工#1

同时绘制多个函数的曲线图

%% 绘制曲线图
% 将曲线图公式赋值给funcList
% 将曲线图名称赋值给legendList
%%
funcList = cell(1,2);
funcList{1} = @(x) 1-1./x;
funcList{2} = @(x) (1-1/10.0)/log(10)*log(x);
legendList = ["y = 1 - 1/x", "y = ln(x)"];
% 创建 x 的取值范围
x = linspace(1, 10, 100);

% 绘制曲线图
figure;
for i = 1:length(funcList)
    plot(x, funcList{i}(x));
    hold on;
end
hold off;

% 添加标题和图例
title('Curves');
legend(legendList);

% 设置坐标轴标签
xlabel('x');
ylabel('y');

% 显示网格线
grid on;