当前位置:网站首页>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 .
边栏推荐
- 图解 Google V8 # 19 :异步编程(二):V8 是如何实现 async/await 的?
- Repair method for win10 subsystem WSL if the passwords of root and other users are forgotten
- Database application
- OpenCV和Image之间的转换(亲测有效)
- Pytoch modifies the hook source code to obtain per layer output parameters (with layer name)
- 【二叉树】最大二叉树 II
- Unity2d-- add keys to animation and bind events
- [mrctf2020]ezpop-1 | PHP serialization
- C language score ranking
- 想转行,但不知道自己要做什么工作比较好?
猜你喜欢

【机器学习Q&A】数据抽样和模型验证方法、超参数调优以及过拟合和欠拟合问题

C language irony

【MySQL 06】linux + Docker容器环境中备份和还原MySQL数据库

What is idempotency? Detailed explanation of four interface idempotence schemes!

一次 Keepalived 高可用的事故,让我重学了一遍它!

C语言 素数对猜想

The (3n+1) conjecture that C language kills people without paying for their lives

当大学毕业感到迷茫怎么办?

js返回内容被unicode编码

Implementation of a simple camera based on pyqt5
随机推荐
假離婚變成真離婚,財產怎麼辦
001_ layout
Implementation of a simple camera based on pyqt5
Understand AQS principle (flow chart and synchronous queue diagram)
C语言 成绩排名
假离婚变成真离婚,财产怎么办
Electron FAQ 54 - make your own fireworks based on electron
GeoTools:WKT、GeoJson、Feature、FeatureCollection相互转换常用工具
Embedded exit (review and release)
cookie加密8
GeoTools WKT坐标系转换
Database application
004_ icon
C语言 素数对猜想
Embedded test template
Cookie encryption 12
[binary tree] maximum binary tree II
Leetcode 46 Full arrangement (February 15, 2022)
003_ color
[MySQL 04] sauvegarde et restauration de la base de données MySQL sous Linux en utilisant MySQL Workbench 8.0 ce