当前位置:网站首页>Matlab | those matlab tips you have to know (2)
Matlab | those matlab tips you have to know (2)
2022-07-28 00:28:00 【slandarer】
1: Real time script control
Real time script should be used by most people , But there are not many people who should use real-time script controls , How to put it? , It should be a module that is more convenient to adjust parameters . Click the icon button to insert various types of controls :

After inserting, double-click the control to set its properties :

A few simple examples ( Because push can't display controls , Therefore, the code given is a control free version , Please add controls by yourself , Or download the network disk compressed package :
【 link 】:https://pan.baidu.com/s/15JxprFG8B10DsocdwzqqLQ?pwd=slan
【 Extraction code 】:slan
Butterfly thread

a=3.5;
clc;cla;clf
x=linspace(0,2*pi,500);
hdl=polarplot(x,sin(x)+sin(a.*x).^3,'LineWidth',1.5);
ax=gca;ax.RTick=[];
Discolored rose

clc;cla;clf
CMAP="parula";
[x,t]=meshgrid((0:24)./24,(0:0.5:575)./575.*20.*pi+4*pi);
p=(pi/2)*exp(-t./(8*pi));
change=sin(15*t)/150;
u=1-(1-mod(3.6*t,2*pi)./pi).^4./2+change;
y=2*(x.^2-x).^2.*sin(p);
r=u.*(x.*sin(p)+y.*cos(p));
h=u.*(x.*cos(p)-y.*sin(p));
surface(r.*cos(t),r.*sin(t),h,'EdgeAlpha',0.1,...
'EdgeColor',[0 0 0],'FaceColor','interp')
colormap(CMAP)
grid on
view(45,45)
Rotate polygon

lenRatio=0.19;
numEdge=7;
numPolygon=14;
clc;cla;clf
theta=linspace(0,2*pi,numEdge+1);
X=cos(theta);X(end)=[];
Y=sin(theta);Y(end)=[];
fill(X,Y,[0,0,0],'FaceColor','none');
hold on;
axis equal
axis([-1,1,-1,1])
for i=1:numPolygon
tX=[X(2:end),X(1)];
tY=[Y(2:end),Y(1)];
X=(tX-X).*lenRatio+X;
Y=(tY-Y).*lenRatio+Y;
fill(X,Y,[0,0,0],'FaceColor','none');
end
hold off
2: Translucent line chart
Line graph function on the official website plot The introduction tells us how to change the thickness , How to adjust the mark style , How to adjust the color , But it doesn't tell us how to set transparency , But in fact plot Of color The attribute looks like rgb value , In fact, it can be rgba value , We put the original rgb Change triples to quadruples to set transparency , for example :
x=0:.1:4*pi;
hold on
plot(x,sin(x),'LineWidth',2,'Color',[1,0,0,0.5]) % Red , transparent 50%
plot(x,cos(x),'LineWidth',2,'Color',[0,0,1,0.5]) % Blue , transparent 50%

3: MATLAB Bring your own color (lines)
The system comes with discrete colors , Various values on the official website :

But there is actually a built-in function lines You can get these basic colors : for example :
lines(1)
lines(2)
ans =
0.0000 0.4470 0.7410
ans =
0.0000 0.4470 0.7410
0.8500 0.3250 0.0980
Another example :
% Generate 18 One color
cList=lines(18);
x=0:.1:4*pi;
hold on
% Circular drawing
for i=1:18
plot(x,sin(x+i*.1).*0.9^i,'Color',cList(i,:),'LineWidth',1.5)
end

4: Batch notes
The simplest multi line comment is to select multiple lines and click the icon button , The button next to it is to cancel multi line comment :

Of course, we count cards : Preset -> Shortcut -> Search for comments , It can also be found that it can be used Ctrl+R Multiline comment , use Ctrl+T uncomment :

Of course %{ And %} It is also a good method for multi line annotation :

5: A few codes appear Chinese garbled
There are many possible reasons for Chinese garbled code , Sorting out an article to deal with all the situations is also very troublesome , Here is a general solution , Is that there will be garbled code m The file suffix consists of .m Change it to .txt Then copy all the contents to the new m File can .
6: Real root
matlab Use ^ perhaps power To find the odd root of a negative number , The default is virtual root , Realistic roots can be used nthroot function :
r1=(-3)^(1/3)
r2=power(-3,1/3)
r3=nthroot(-3,3)
r1 =0.7211 + 1.2490i
r2 =0.7211 + 1.2490i
r3=-1.4422
7: Show only part of the legend
Name each drawing object and treat it as legend The first parameter of the function is ok , for instance :
x=0:.2:4*pi;
% Draw some pictures casually
hold on;grid on
p1=plot(x,sin(x),'-.','LineWidth',2);
p2=plot(x,sin(0.5.*x),'--','LineWidth',2);
p3=plot(x,sin(x).^2,':','LineWidth',2);
% to 1、3 Image as legend
legend([p1,p3],{
'sin(x)','sin^2(x)'})

8: Generate latex And mathml The formula
Here is an example directly on the official website :
latex Formula generation
syms x
S = [sym(1)/3 x; exp(x) x^2]
S = ( 1 3 x e x x 2 ) S=\left(\begin{array}{cc} \frac{1}{3} & x\\ {\mathrm{e}}^x & x^2 \end{array}\right) S=(31exxx2)
chr = latex(S)
Running results :
chr =
'\left(\begin{array}{cc} \frac{1}{3} & x\\ {\mathrm{e}}^x & x^2 \end{array}\right)'
MathML Formula generation
You can try directly MathML Formula copied to non WPS Of word file , Formulas will be generated directly , however MATLAB For simple formulas , It generates MathML Can be directly in word Generate formula , Don't expect anything complicated ...
syms x
f = 1/exp(x^2);
chr=mathml(f)
Running results :
chr =
'<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'>
<msup>
<mo>ⅇ</mo>
<mrow>
<mo>-</mo>
<msup>
<mi>x</mi>
<mn>2</mn>
</msup>
</mrow>
</msup>
</math>
'
边栏推荐
- require、loadfile、dofile、load、loadstring
- [BRE]软件构建发布自动化
- XSS payload learning browser decoding
- 窗口函数over
- Have you ever seen this kind of dynamic programming -- the stock problem of state machine dynamic programming (Part 2)
- Description and analysis of main parameters of R language r native plot function and lines function (type, PCH, CEX, lty, LWD, col, xlab, ylab)
- It was dog days, but I was scared out of a cold sweat: how far is the hidden danger of driving safety from us?
- 渲染问题
- 好漂亮的彩虹
- Esp8266----- mqtt cloud device on cloud
猜你喜欢

A few lines of code can easily realize the real-time reasoning of paddleocr. Come and get!

窗口函数over

A great thinking problem cf1671d insert a progression

Intel joins hands with hanshuo and Microsoft to release the "Ai + retail" trick!

What foundation does Yolo need? How to learn Yolo?
Database tuning - principle analysis and JMeter case sharing

MFC prompts that this application has requested the runtime to terminate it in an unused way editbox box has been deleted and is still in use

Glory launched a number of products at the same time. The price of notebook magicbook V 14 starts from 6199 yuan

冲量在线出席2022数据要素安全流通论坛—政务领域专场,助力行业政务大数据建设创新发展

几行代码轻松实现对于PaddleOCR的实时推理,快来get!
随机推荐
If we were the developer responsible for repairing the collapse of station B that night
英特尔发布开源AI参考套件
Database tuning - principle analysis and JMeter case sharing
Mqtt---mqtt.fx client software
Jin's thinking
Common errors reported by ant sword
C# 事件相关的练习代码。
Is there a general formula for tens of millions of players? B station is underestimated as a hot money opportunity!
火狐浏览器 Firefox 103 发布,提升高刷新率显示器下的性能
In the third week of July, the list of feigua data station B up main ranking list was released!
【读书会第13期】音视频文件的封装格式
永州植物细胞实验室建设布局方案
require、loadfile、dofile、load、loadstring
公司7月来了个软件测试工程师,一副毛头小子的样儿,哪想到是新一代卷王...
服务器中毒了——菜是原罪
Shell(3)
JS ATM机输出
学yolo需要什么基础?怎么学YOLO?
New media content output method - short video
Cache与MMU管理