# MATLAB_Useful_Snippet **Repository Path**: pzhengwf/MATLAB_Useful_Snippet ## Basic Information - **Project Name**: MATLAB_Useful_Snippet - **Description**: MATLAB编程过程中遇到的不错的小功能 - **Primary Language**: Matlab - **License**: BSD-3-Clause - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2019-06-05 - **Last Updated**: 2022-01-08 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # MATLAB_Useful_Snippet # 介绍 MATLAB编程过程中遇到的不错的小功能、小代码段 # 软件架构 单个独立的小功能堆在这里 # 安装教程 1. 各个小功能独立的,无任何关系 # 使用说明 ## 1.MATLAB Data Cursor游标显示数据更改 方法: 1)创建CallBack,代码结构可以右键Data Cursor,游标具有如下属性: DataCursorManager (具有属性): SnapToDataVertex: 'on' DisplayStyle: 'datatip' DefaultExportVarName: 'cursor_info' UpdateFcn: @DataCursor_Callback_ex Enable: 'on' Figure: [1x1 Figure] UpdateFcn属性设置回调函数,可以自己编写这个回调函数,回调函数格式是固定的,可以在右键'编辑文本更新函数'内打开模板。我的修改如下: function output_txt = DataCursor_Callback_ex(obj,event_obj) % Display the position of the data cursor % obj Currently not used (empty) % event_obj Handle to event object % output_txt Data cursor text string (string or cell array of strings). global time_str ; pos = get(event_obj,'Position'); output_txt = {['X: ',time_str(pos(1),:)],... % 此处的pos(1)后的数字,即X轴的数据游标的显示精度位数 ['Y: ',num2str(pos(2),5)]}; % 此处的pos(2)后的数字,即Y轴的数据游标的显示精度位数 % If there is a Z-coordinate in the position, display it as well if length(pos) > 2 output_txt{end+1} = ['Z: ',num2str(pos(3),5)]; % 此处的pos(3)后的数字,即Z轴的数据游标的显示精度位数 end 我把X坐标原来现实当前索引,改为显示字符串时间time_str,time_str在其他地方定义的全局变量 2)其他绘图函数内,设置这个回调函数,设置方法如下: dcm_obj = datacursormode(gcf); set(dcm_obj,'UpdateFcn',@DataCursor_Callback_ex) 以上2步,则自主更改游标显示修改完成。 注意:把自己的函数和DataCursor_Callback_ex回到函数都放在path路径下,要索引的到这个回调函数 显示效果如下: ![MATLAB游标数据设置](https://gitee.com/pzhengwf/MATLAB_Useful_Snippet/raw/master/image/data_cursor_set.bmp "MATLAB游标数据设置效果") 2. xxxx 3. xxxx #### 参与贡献 1. Fork 本仓库 2. 新建 Feat_xxx 分支 3. 提交代码 4. 新建 Pull Request #### 码云特技 1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md 2. 码云官方博客 [blog.gitee.com](https://blog.gitee.com) 3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解码云上的优秀开源项目 4. [GVP](https://gitee.com/gvp) 全称是码云最有价值开源项目,是码云综合评定出的优秀开源项目 5. 码云官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) 6. 码云封面人物是一档用来展示码云会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)