当前位置:网站首页>Matlab 2012a drawing line segment with arrow
Matlab 2012a drawing line segment with arrow
2022-06-30 01:56:00 【Intimes】
Matlab 2012a Self contained line Function can draw line segments , But the arrow cannot be drawn .
There is also a function called annotation, You can draw arrow segments , But unfortunately , Only in 0 To 1 Draw within the scope of , And may be out of some special consideration .
therefore , You need self-made functions to draw line segments with arrows . I found a code on the Internet , But in Matlab 2012a There are problems running in the environment , So some changes have been made . It's ready to run .
First, let's look at the effect :

The effect is quite satisfactory , You can draw beautiful arrow segments , And the scope is not limited to 0 To 1 Within the scope of , Of course , Operational efficiency and other aspects can still be improved .
Let's go straight to the code ”
clc;clear;
x1 = [1 2];
y1 = [5 7];
h1 = drawarrow(x1,y1);
hold on;
axis([0 5 0 7]);
x2 = [3 1];
y2 = [3 5];
h2 = drawarrow(x2,y2);This is the test program , Here are the functions
function h = drawarrow(x,y,lineType,ax)
% https://blog.csdn.net/qq_41093957/article/details/115256114
% The biggest problem with this program is Changed the plot The scope of the So that the position of the line segment is wrong
switch nargin
case 2
lineType='arrow';
ax=gca;
case 3
ax=gca;
end
% Resize coordinates to fit arrow length
% xlimraw=get(ax,'XLim');
% ylimraw=get(ax,'YLim');
xlim=get(ax,'XLim');
ylim=get(ax,'YLim');
xlimmin=xlim(1);xlimmax=xlim(2);
ylimmin=ylim(1);ylimmax=ylim(2);
if xlimmin>min(x(1),y(1)), xlimmin=min(x(1),y(1));end
if xlimmax<max(x(1),y(1)), xlimmax=max(x(1),y(1));end
if ylimmin>min(x(2),y(2)), ylimmin=min(x(2),y(2));end
if ylimmax<max(x(2),y(2)), ylimmax=max(x(2),y(2));end
% ax.XLim = [xlimmin,xlimmax];
% ax.YLim = [ylimmin,ylimmax];
set(ax,'XLim',[xlimmin,xlimmax]);
set(ax,'YLim',[ylimmin,ylimmax]);
xlim=get(ax,'XLim');
ylim=get(ax,'YLim');
% xlim=ax.XLim;
% ylim=ax.YLim;
pos=get(ax,'Position');
x_ratio = pos(3)/(xlim(2)-xlim(1));
y_ratio = pos(4)/(ylim(2)-ylim(1)); % Zoom ratio
orig_pos=[-xlim(1)*x_ratio+pos(1),-ylim(1)*y_ratio+pos(2)]; % figure The coordinates of the origin in the coordinate system
x=x.*[x_ratio,y_ratio];y=y.*[x_ratio,y_ratio];
x=x+orig_pos;y=y+orig_pos;
h = annotation(lineType,[x(1),y(1)],[x(2),y(2)]);
% set(ax,'XLim',xlimraw);
% set(ax,'YLim',ylimraw);
end
Here I would like to thank the original author . There is no problem with his procedure , Just maybe not 2012a Environment , After the change , You can use it .
边栏推荐
猜你喜欢

C语言 素数对猜想

Cookie encryption 15 login encryption

What should be paid attention to in the design and production of the Urban Planning Museum
![[graph neural network] overview of graph classification learning [2]: graph classification based on graph neural network](/img/5f/b23b64eed7f28ffd92c122b6859e2d.png)
[graph neural network] overview of graph classification learning [2]: graph classification based on graph neural network

C语言 数组元素循环右移问题

C语言 成绩排名

cookie加密9

cookie加密8

C语言 说反话

C语言 写出这个数
随机推荐
搞透AQS原理(流程圖及同步隊列圖解)
Oppo mobile phone search
App test related tools
Want to change careers, but don't know what you want to do?
Pytorch中transforms的用法整理
Cookie encryption 10
A summary of the quantification of deep network model
工具与生活服务
Where can I find a pre training model for pytoch model training?
Comprendre le principe AQS (organigramme et schéma de file d'attente synchrone)
How to deal with occasional bugs?
Tools and life services
Using grpcui to test asp Net core grpc service
【机器学习Q&A】余弦相似度、余弦距离、欧式距离以及机器学习中距离的含义
Add a second network card (network interface NIC) for the virtual machine in azure portal in 2 minutes
Mobaihe cm201-2-ch-hi3798mv300-300h-emmc and NAND_ Infrared Bluetooth voice_ Brush firmware package
【PyTorch实战】生成对抗网络GAN:生成动漫人物头像
(1) Basic learning - figure out the difference between pin, pad, port, IO and net
js返回内容被unicode编码
cookie加密8