MATLAB 给显示文本添加下标,控制颜色等

clear all;close all;
dd = {'<html><b><font color ="black"> y = x + 0.5x<sup>2</sup></b>';
    '<html><b><font color ="black"> y = x+ 0.5x<sup>3</sup></b>';
    '<html><b><font color ="black"> y = x + 0.5x<sup>2</sup>+0.2x<sup>3</sup></b>'};
figure('name','','menubar','none','numbertitle','off',...
    'position',[600 200 600 600],'color',[1 1 1]);
pp = uipanel('parent',gcf,'Title','参数选择','units',...
    'pixel','position',[10 550 500 50],'Backgroundcolor',[1 1 1]);
ff1=uicontrol('parent',pp,'style','popupmenu','string',num2str([1:10]'),...
    'position',[50 0 50 30],'units','pixel' ,'foregroundcolor',[0 0 0],'fontsize',8,...
    'Value',3,'callback',@getf);
ff2=uicontrol('parent',pp,'style','popupmenu','string',num2str([1:10]'),'Backgroundcolor',[1 1 1],...
    'position',[150 0 50 30],'units','pixel' ,'foregroundcolor',[0 0 0],'fontsize',8,...
    'Value',5,'callback',@getf);
fff1=uicontrol('parent',pp,'style','text','string','F1(Hz)','Backgroundcolor',[1 1 1],...
    'position',[5 0 50 30],'units','pixel' ,'foregroundcolor',[0 0 0],'fontsize',8);
fff2=uicontrol('parent',pp,'style','text','string','F2(Hz)','Backgroundcolor',[1 1 1],...
    'position',[100 0 50 30],'units','pixel' ,'foregroundcolor',[0 0 0],'fontsize',8);
fff3=uicontrol('parent',pp,'style','text','string','放大函数','Backgroundcolor',[1 1 1],...
    'position',[300 0 50 30],'units','pixel' ,'foregroundcolor',[0 0 0],'fontsize',8);
fff33=uicontrol('parent',pp,'style','popupmenu','string',dd,'Backgroundcolor',[1 1 1],...
    'position',[360 0 130 30],'units','pixel' ,'foregroundcolor',[0 0 0],'fontsize',8,...
    'callback',@getf);

%% 参数设置
% 两个正弦波叠加,频率分别为3Hz和5Hz
warning off
global f1 f2 ff1 ff2 fff33
fs = 100;
ts = 1/fs;
t = 0:ts:10;
f1 = ff1.Value;
f2 = ff2.Value;
sig1 = sin(2*pi*f2*t)+sin(2*pi*f1*t);
signal = sig1+0.5*sig1.*sig1;
% signal = repmat(sig2,1,10);
len = length(signal);
df = fs/len;%频域间隔
spectrum = fftshift(abs(fft(signal)));
subplot(2,1,1);%两行一列分图,第一幅图
plot(t,signal);
get(gca,'position');
set(gca,'position',[ 0.1300    0.5338    0.7750    0.3412])
title('timeDomain');
subplot(2,1,2);
spectrum = spectrum(round(len/2):len);
stem(0:df:df*(len-round(len/2)),spectrum,'MarkerSize',2);%横坐标修正的单边频谱
get(gca,'position');
set(gca,'position',[0.1300    0.08    0.7750    0.3412])
title('frequenceDomain');
[yy xx] = findpeaks(spectrum);
for i =1:length(xx)
text((xx(i)+2)*df,yy(i),[num2str(round(xx(i)/10))])
end


%%
function getf(~,~)
global f1 f2 ff1 ff2 fff33 
f1 = ff1.Value;
f2 = ff2.Value;
coeffient =  fff33.Value;
fs = 100;
ts = 1/fs;
t = 0:ts:10;
f1 = ff1.Value;
f2 = ff2.Value;
sig1 = sin(2*pi*f2*t)+sin(2*pi*f1*t);
if coeffient == 1
signal = sig1+0.5*sig1.*sig1;
elseif coeffient == 2
    signal = sig1+0.5*sig1.*sig1.*sig1;
else
    signal = sig1+0.2*sig1.*sig1.*sig1+0.5*sig1.*sig1;
end
% signal = repmat(sig2,1,10);
len = length(signal);
df = fs/len;%频域间隔
spectrum = fftshift(abs(fft(signal)));
subplot(2,1,1);%两行一列分图,第一幅图
plot(t,signal);
get(gca,'position');
set(gca,'position',[ 0.1300    0.5338    0.7750    0.3412])
title('timeDomain');
subplot(2,1,2);
spectrum = spectrum(round(len/2):len);
stem(0:df:df*(len-round(len/2)),spectrum,'MarkerSize',2);%横坐标修正的单边频谱
get(gca,'position');
set(gca,'position',[0.1300    0.08    0.7750    0.3412])
title('frequenceDomain');
[yy xx] = findpeaks(spectrum);
for i =1:length(xx)
text((xx(i)+2)*df,yy(i),[num2str(round(xx(i)/10))])
end
end

在这里插入图片描述
重点看这里:

dd = {'<html><b><font color ="black"> y = x + 0.5x<sup>2</sup></b>';
    '<html><b><font color ="black"> y = x+ 0.5x<sup>3</sup></b>';
    '<html><b><font color ="black"> y = x + 0.5x<sup>2</sup>+0.2x<sup>3</sup></b>'};

在MATLAB中,只有少数地方能够用LaTeX语言控制文本,在一般的Text里面还需要用HTML来控制,例如:

dd = {'<html><b><em><font color ="black"> y = x + 0.5x<sup>2</sup></b></em>';%<em>表示斜体强调
    '<html><b><font color ="black"> y = x+ 0.5x<sup>3</sup></b>';
    '<html><b><font color ="black"> y = x + 0.5x<sup>2</sup>+0.2x<sup>3</sup></b>'};

第一行为斜体加粗,第二行为斜体
在这里插入图片描述

<sup>3</sup> 表示上标
<sub>3</sub> 表示下标
<b>This text is bold</b> 表示加粗
<i>This text is italic</i> 斜体
<small>This text is small</small> 小字号
<big>This text is big</big> 大字号

在这里插入图片描述
更多属性查看

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

肆拾伍

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值