在 MATLAB 中使用代码将 * 更改为 U00D7 乘法符号 (×)

问题描述 投票:0回答:1

我正在使用 MATLAB 的

fitlm
函数来分析一些测试数据,然后根据文档绘制“原始输出”。 (matlab
fitlm
文档
)

这个

plot(mdl)
有一个自动生成的图例,里面有线性模型模型的方程,形式为:

y = m*x+c

我需要将这个星号(

*
)更改为乘法符号U00D7,(
×
),这样:

y = m × x+c

是否可以使用代码来完成此操作还是需要手动更改?

clear
clc

%Make test data
%----------------------------
x1 = 1:0.01:3;
r = -1 + (1+1)*rand(1,201);
x1 = x1 + r;

y1 = 1:0.01:3;
r = -1 + (1+1)*rand(1,201);
y1 = y1 + r;

x1 = x1';
y1 = y1';
label1 = zeros(length(y1),1);

Tclust1 = [label1,x1,y1];
%----------------------------
x2 = 4:0.01:6;
r = -1 + (1+1)*rand(1,201);
x2 = x2 + r;

y2 = 10:0.01:12;
r = -1 + (1+1)*rand(1,201);
y2 = y2 + r;

x2 = x2';
y2 = y2';
label2 = ones(length(y2),1);

Tclust2 = [label2,x2,y2];

%----------------------------
x3 = 5:0.01:7;
r = -1 + (1+1)*rand(1,201);
x3 = x3 + r;

y3 = 11:0.01:13;
r = -1 + (1+1)*rand(1,201);
y3 = y3 + r;

x3 = x3';
y3 = y3';
label3 = label2+1;

Tclust3 = [label3,x3,y3];
%----------------------------
T = [Tclust1;Tclust2;Tclust3];

%Prep for LM -------------------------------------------------------------
%Classify by labels
Label_idx = zeros(length(T(:,1)),1);

for qq = 1:length(Label_idx)  
    if T(qq,1) > 0
        Label_idx(qq) = 1;
    end
end

for qq = 1:length(Label_idx)
    if T(qq,1) > 1
        Label_idx(qq) = 2;
    end
end

%dummy variables
for qq = 1:length(Label_idx)
    if Label_idx(qq) == 0
        Label_1(qq) = 1;
    else
    Label_1(qq) = 0;
    end
end

Label_1 = Label_1';

for qq = 1:length(Label_idx)
    if Label_idx(qq) == 2
        Label_2(qq) = 1;
    else
    Label_2(qq) = 0;
    end
end

Label_2 = Label_2';

%Do the Linear modelling -------------------------------------------------

%Input predictor
pred = (T(:,2));
%Input comparator
comp = (T(:,3));

%interaction parameters
int_lo = pred.*Label_1;
int_hi = pred.*Label_2;

%predictors
    X = [pred,Label_1,Label_2,int_lo,int_hi];
    LR_mdl = fitlm(X,comp);

%plot ==========================================================
plot(LR_mdl)

    
    

        
        
matlab legend matlab-figure
1个回答
0
投票

这将完成这项工作:

h = findobj(gcf, 'type', 'legend');
h.String{2} = strrep(h.String{2}, '*', char(hex2dec('D7')));
© www.soinside.com 2019 - 2024. All rights reserved.