合理使用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中调用时,注意方式。
人就像是被蒙着眼推磨的驴子,生活就像一条鞭子;当鞭子抽到你背上时,你就只能一直往前走,虽然连你也不知道要走到什么时候为止,便一直这么坚持着。
浙公网安备 33010602011771号