当前位置:网站首页>Matlab | those matlab tips you have to know (4)
Matlab | those matlab tips you have to know (4)
2022-07-28 00:28:00 【slandarer】
Hey, hey, hey, here comes the fourth issue :
1: Convert decimals into fractions and extract numerators and denominators
a=2065/2013 ;
b=split(rats(a),'/')
c=str2num(b{
1})
d=str2num(b{
2})
b =
2×1 cell Array
{’ 2065’}
{'2013 ’ }
\,
c =
2065
\,
d =
2013
2: Cell and array conversion
2.1: Cell rotation value array
Extract all the elements and arrange them in a column :
A={
1,2,3;4,5,6;7,8,9}
% Extract all the elements and arrange them in a column
B1=[A{
:}]'
A =
3×3 cell Array
{[1]} {[2]} {[3]}
{[4]} {[5]} {[6]}
{[7]} {[8]} {[9]}
\,
B1 =
1
4
7
2
5
8
3
6
9
Convert a numerical cell array to a numerical array :
A={
1,2,3;4,5,6;7,8,9};
% Convert a numerical cell array to a numerical array
B2=cell2mat(A)
% The following methods are also acceptable, but the speed is slow
% B2=reshape([A{
:}],size(A))
B2 =
1 2 3
4 5 6
7 8 9
String cell to cell numeric array :
C={
'12','34';'56','78'}
D=reshape(str2num(char(C)),size(C))
C =
2×2 cell Array
{‘12’} {‘34’}
{‘56’} {‘78’}
\,
D =
12 34
56 78
2.2: Numerical array to cell
Block and transform cells
A=[1,2,3;4,5,6]
% The line is divided into two pieces, one for each
% The column is divided into two parts 1 Row sum 2 That's ok
B=mat2cell(A,[1,1],[1,2])
A =
1 2 3
4 5 6
\,
B =
2×2 cell Array
{[1]} {[2 3]}
{[4]} {[5 6]}
No block to cell , The following two methods are equivalent , But obviously, the second method is much simpler :
A=[1,2,3;4,5,6];
B1=mat2cell(A,ones(1,size(A,1)),ones(1,size(A,2)))
B2=num2cell(A)
B1 =
2×3 cell Array
{[1]} {[2]} {[3]}
{[4]} {[5]} {[6]}
\,
B2 =
2×3 cell Array
{[1]} {[2]} {[3]}
{[4]} {[5]} {[6]}
3: Attribute cell
For this property, you need to set it repeatedly many times :
x=0:.2:4*pi;
hold on
plot(x,sin(x),'-s','LineWidth',2,'MarkerSize',10);
plot(x,sin(0.5.*x),'-^','LineWidth',2,'MarkerSize',10);
plot(x,sin(x).^2,'-o','LineWidth',2,'MarkerSize',10);
Save it in the cell array :
x=0:.2:4*pi;
hold on
tc={
'LineWidth',2,'MarkerSize',10};
plot(x,sin(x),'-s',tc{
:});
plot(x,sin(0.5.*x),'-^',tc{
:});
plot(x,sin(x).^2,'-o',tc{
:});

4: Delete nan value
One dimensional vector :
oriData=[1 nan nan 4 nan 5 6]
oriData(isnan(oriData))=[]
oriData =
1 NaN NaN 4 NaN 5 6
\,
oriData =
1 4 5 6
Delete with nan The line of :
oriData=[1 2;nan 4;5 6;7 nan]
tData=sum(oriData,2);
oriData(isnan(tData),:)=[]
oriData =
\,\,\,\,\,\, 1 \,\,\,\,\,\, 2
NaN \,\,\,\,\,\, 4
\,\,\,\,\,\, 5 \,\,\,\,\,\, 6
\,\,\,\,\,\, 7 NaN
\,
oriData =
1 2
5 6
Of course, if you want to delete nan The column of , Change the code to :
tData=sum(oriData,1);
oriData(:,isnan(tData))=[]
Of course, draw inferences from one instance , use isinf Function can delete infinite value .
5: Get workspace variables
as everyone knows whos Function can get the current workspace variable :

And in functions or in app in ,whos The function gets the variables in the current field instead of the workspace variables . have access to evalin The function get is specified as base Variables in the workspace :
evalin('base','whos')
6: Merge multiple fig For the same fig
If we had two fig file , Respectively called 1.fig,2.fig:

Merge into one fig Code :
fig1=open('1.fig');
fig2=open('2.fig');
figure()
ax1=subplot(2,1,1);
copyobj(fig1.Children.Children,ax1)
delete(fig1)
ax2=subplot(2,1,2);
copyobj(fig2.Children.Children,ax2)
delete(fig2)

7: Merge multiple fig To the same axes
Still use some fig file :
fig1=open('1.fig');
fig2=open('2.fig');
figure()
ax=gca;
copyobj(fig1.Children.Children,ax)
copyobj(fig2.Children.Children,ax)
delete(fig1)
delete(fig2)

边栏推荐
- MQTT----mqtt.fx客户端软件
- threejs个人笔记
- Application scenario Display of metauniverse
- 理解双亲委派模式
- 永州出入境检验实验室建设那些事
- Yongzhou water quality testing laboratory construction: Furniture description
- It was dog days, but I was scared out of a cold sweat: how far is the hidden danger of driving safety from us?
- [gwctf 2019] boring lottery
- Server open sensitive port
- Intel joins hands with hanshuo and Microsoft to release the "Ai + retail" trick!
猜你喜欢

MATLAB | 那些你不得不知道的MATLAB小技巧(一)

BuildForge 资料

蚁剑常见报错

Implement Gobang game with C language

强强协同,共拓发展!英特尔与太一物联举办 AI 计算盒聚合服务研讨会

物联网有助于应对气候变化的 3 种方式

2022年中国网络视频市场年度综合分析

图片提取文字很神奇?试试三步实现OCR!

code review 工具

Promoting cloud network integration and building a digital economy: Intel unveiled the 5th Digital China Construction Summit - cloud ecosystem Conference
随机推荐
Have you ever seen this kind of dynamic programming -- the stock problem of state machine dynamic programming (Part 2)
英特尔发布开源AI参考套件
JVM memory model
永州植物细胞实验室建设布局方案
[极客大挑战 2019]RCE ME
How difficult is it to apply for a doctorate under the post system in northern Europe?
永州分析实验室建设选址概述
永州清洁级动物实验室建设选址注意事项
【读书会第13期】音视频文件的封装格式
永州水质检测实验室建设:家具说明
AI briefing how to use loss surfaces a model integration
「图神经网络:基础、前沿与应用」最新IJCAI2022教程
View the construction details of Yongzhou dioxin Laboratory
每次读取一行字符串输入(有待补充)
Understand the parental delegation model
BuildForge 资料
数据中台的那些“经验与陷阱”
JS event propagation capture stage bubbling stage onclick addeventlistener
永州二恶英实验室建设细节查看
Mqtt---mqtt.fx client software