合理使用strcat和num2str让legend更加的自动划

代码:
复制代码
%% higher order polynomials
clc;
clear all;
close all;

x=[-1.2 -0.5 0.3 0.9 1.8 2.6 3.0 3.5];
y=[-15.6 -8.5 2.2 4.5 6.6 8.2 8.9 10.0];

figure('Position',[10 2050 1420 420]);
for i= 1:3
    subplot(1,3,i);
    p=polyfit(x,y,i);
    xfit=x(1):0.1:x(end);
    yfit=polyval(p,xfit);
    plot(x,y,'ro', xfit,yfit,'b-');
    set(gca, "FontSize",14);
    ylim([-17 11]);
    dp(i,:)=strcat(num2str(i),' Data points');
    fc(i,:)=strcat(num2str(i),' Fitted cureve');
    legend(dp(i,:), fc(i,:));
end
复制代码

虽然在循环中,通过将数值和字符串结合后生成vector,在legend中调用时,注意方式。

posted @   叕叒双又  阅读(2)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
点击右上角即可分享
微信分享提示