当前位置:网站首页>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 .
边栏推荐
- Comprendre le principe AQS (organigramme et schéma de file d'attente synchrone)
- 【机器学习Q&A】准确率、精确率、召回率、ROC和AUC
- OpenCV和Image之间的转换(亲测有效)
- Que se passe - t - il si un faux divorce devient un vrai divorce?
- Three questions from the boss
- Derivation of univariate polynomial in C language
- 模块导入reload方法
- C语言 成绩排名
- [MySQL 04] use MySQL workbench 8.0 CE to back up and restore MySQL databases in Linux
- 什么是幂等性?四种接口幂等性方案详解!
猜你喜欢
Spark 离线开发框架设计与实现
cookie加密8
[graph neural network] summary of graph classification study [3]: evaluation of graph classification methods and future research directions
012_ switch
JS content confusion, return content encryption
AI landing manufacturing: intelligent robots should have these four abilities
C语言 数组元素循环右移问题
C language continues (3n+1) conjecture
Embedded test template
C语言 换个格式输出整数
随机推荐
Oppo mobile phone search
What is idempotency? Detailed explanation of four interface idempotence schemes!
C语言 说反话
Geotools: common tools for mutual conversion of wkt, geojason, feature and featurecollection
Simple implementation of unity object pool
当大学毕业感到迷茫怎么办?
Que se passe - t - il si un faux divorce devient un vrai divorce?
[MRCTF2020]Ezpop-1|php序列化
Application features and functions of painting Aquarium
Derivation of univariate polynomial in C language
cookie加密8
Embedded exit (review and release)
Want to change careers, but don't know what you want to do?
【MySQL 04】使用MySQL Workbench 8.0 CE 备份及恢复Linux中的MySQL数据库
What to remember about the penalty for deduction of points in Item 1
手势数字启蒙学习机
Design and implementation of spark offline development framework
JS content confusion, return content encryption
win10子系统 WSL如果root和其他用户的密码都忘记的修复方法
Unity2D--给动画添加关键帧并绑定事件