当前位置:网站首页>[matlab] matlab drawing Series II 1. Cell and array conversion 2. Attribute cell 3. delete Nan value 4. Merge multiple figs into the same Fig 5. Merge multiple figs into the same axes
[matlab] matlab drawing Series II 1. Cell and array conversion 2. Attribute cell 3. delete Nan value 4. Merge multiple figs into the same Fig 5. Merge multiple figs into the same axes
2022-07-24 14:33:00 【Love coldplay】
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)

边栏推荐
- “00后”来了!数睿数据迎来新生代「无代码」生力军
- AtCoder Beginner Contest 261 F // 树状数组
- CAS atomic type
- Rest style
- Time series of machine learning
- 【NLP】下一站,Embodied AI
- [oauth2] III. interpretation of oauth2 configuration
- 不要灰心,大名鼎鼎的YOLO、PageRank影响力爆棚的研究,曾被CS顶会拒稿
- The difference and relation among list, set and map
- Nodejs uses the express framework to post the request message "badrequesterror:request aborted"
猜你喜欢

Similarities and differences between nor flash and NAND flash

Maotai ice cream "bucked the trend" and became popular, but its cross-border meaning was not "selling ice cream"

bibliometrix: 从千万篇论文中挖掘出最值得读的那一篇!

Moving the mouse into select options will trigger the mouseleave event processing scheme

电赛设计报告模板及历年资源

VSCode如何调试Nodejs
![Rasa 3.x 学习系列-Rasa [3.2.3] - 2022-07-18 新版本发布](/img/fd/c7bff1ce199e8b600761d77828c674.png)
Rasa 3.x 学习系列-Rasa [3.2.3] - 2022-07-18 新版本发布

After five years of contact with nearly 100 bosses, as a headhunter, I found that the secret of promotion was only four words
![[C language note sharing] - dynamic memory management malloc, free, calloc, realloc, flexible array](/img/3f/35c9ff3be5c0ef781ffcb537287a20.png)
[C language note sharing] - dynamic memory management malloc, free, calloc, realloc, flexible array
![[oauth2] IV. oauth2authorizationrequestredirectfilter](/img/42/fff83a8d477e2f2d07d1f5ad4e4405.png)
[oauth2] IV. oauth2authorizationrequestredirectfilter
随机推荐
Tensorflow framework of deep learning realizes vgg/rnn network / verification code generation and recognition / text classification
Summary of Baimian machine learning
IntelliSense of Visual Studio: 'no members available'
栈与队列——225. 用队列实现栈
Caffe framework and production data source for deep learning
Grpc middleware implements grpc call retry
【机器学习】之 主成分分析PCA
ISPRS2018/云检测:Cloud/shadow detection based on spectral indices for multi/hyp基于光谱指数的多/高光谱光学遥感成像仪云/影检测
[C language note sharing] - dynamic memory management malloc, free, calloc, realloc, flexible array
解决 uni-starter 使用本地函数可以登录微信 但是使用云函数登录失败
Typo in static class property declarationeslint
Extjs4 instance address and Chinese document address
TypeError: Cannot read property ‘make‘ of undefined
Differences between C language pointer and array A and &a, &a[0], etc
Binlog and iptables prevent nmap scanning, xtrabackup full + incremental backup, and the relationship between redlog and binlog
Don't lose heart. The famous research on the explosive influence of Yolo and PageRank has been rejected by the CS summit
DDD based on ABP -- Entity creation and update
本机异步网络通信执行快于同步指令
Rasa 3.x 学习系列-Rasa [3.2.3] - 2022-07-18 新版本发布
Solve the problem that uni starter can log in to wechat with local functions, but fails to log in with cloud functions