MATLAB+GUI:手动修改曲线中的点_matlab如何将一条曲线的数据稍微修改一点-程序员宅基地

技术标签: MATLAB  

本文目的:手动修改已知曲线中的点
功能:
1、可以放缩图像,进行数据点的修改
2、可以选定数据点,并进行修改
3、数据点的修改不能超出相邻点的范围
4、可以移动坐标轴和图像,以方便观察整体图像
5、可以保存修改后的数据
本代码可以自行下载:https://download.csdn.net/download/qq_27261889/10577901

function varargout = movePoints(varargin)
% MOVEPOINTS MATLAB code for movePoints.fig
%      MOVEPOINTS, by itself, creates a new MOVEPOINTS or raises the existing
%      singleton*.
%
%      H = MOVEPOINTS returns the handle to a new MOVEPOINTS or the handle to
%      the existing singleton*.
%
%      MOVEPOINTS('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in MOVEPOINTS.M with the given input arguments.
%
%      MOVEPOINTS('Property','Value',...) creates a new MOVEPOINTS or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before movePoints_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to movePoints_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help movePoints

% Last Modified by GUIDE v2.5 29-Jul-2018 04:49:24

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @movePoints_OpeningFcn, ...
                   'gui_OutputFcn',  @movePoints_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before movePoints is made visible.
function movePoints_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to movePoints (see VARARGIN)

% Choose default command line output for movePoints
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes movePoints wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = movePoints_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global xData yData
xData = textread('xData.txt');
yData = textread('yData.txt');
drag_point(hObject, eventdata, handles)

% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
zoom on;


% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
zoom off;

function drag_point(hObject, eventdata, handles)
global xData yData hl hp flag
flag = 0;
hl = line(xData, yData);
axes(handles.axes1);
distance = max(xData) - min(xData);
factor = 0.05;
axis([min(xData)-distance*factor, max(xData)+distance*factor , min(yData)-distance*factor, max(yData)+distance*factor]);
for i = numel(xData):-1:1
    hp(i) = patch('xdata',xData(i),'ydata',yData(i),...
        'linestyle','none','facecolor','none',...
        'marker','o','markerEdgecolor','k',...
        'markersize', 3, ...
        'buttonDownFcn',@drag,'userdata',i);
end

function drag(src, ~)
global index of
index = get(src,'userdata');
of = get(gcbf,{'WindowButtonMotionFcn','WindowButtonUpFcn'});
set(gcbf,'WindowButtonMotionFcn',@move,'WindowButtonUpFcn',@drop);
    
function move(~, ~)
global index points hl hp xData
points = get(gca,'currentPoint');
xn = points(1);
yn = points(3);
if index>1 && index<size(xData,2)
    if xn<hl.XData(index-1)
        xn = hl.XData(index-1);
    end
    if xn>hl.XData(index+1)
        xn = hl.XData(index+1);
    end
    if yn<hl.YData(index-1)
        yn = hl.YData(index-1);
    end
    if yn>hl.YData(index+1)
        yn = hl.YData(index+1);
    end
end
set(hp(index),'xdata',xn,'ydata',yn)
hl.XData(index) = xn;
hl.YData(index) = yn;

function drop(src,~)
global of
set(src,'WindowButtonMotionFcn',of{1},'WindowButtonUpFcn',of{2});


% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global xData yData flag
flag = 1;
dlmwrite('newX.txt',xData)
dlmwrite('newY.txt',yData)

% --- Executes on mouse press over axes background.
function axes1_ButtonDownFcn(hObject, eventdata, handles)
% hObject    handle to axes1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% axes(handles.axes1);
% zoom on
global flag
if flag==1
    drag_point(hObject, eventdata, handles);
end


% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
axes(handles.axes1);
positionX = get(gca, 'xlim');
% positionY = get(gca, 'ylim');
factor = 0.1;
positionX = positionX - factor * (positionX(2)-positionX(1));
set(gca, 'xlim', [positionX(1), positionX(2)]);
% set(gca, 'ylim', [positionY(1),  positionY(2)]);


% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
axes(handles.axes1);
positionX = get(gca, 'xlim');
% positionY = get(gca, 'ylim');
factor = 0.1;
positionX = positionX + factor * (positionX(2)-positionX(1));
set(gca, 'xlim', [positionX(1), positionX(2)]);

结果展示
初始界面
初始化界面
修改后的界面

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_27261889/article/details/81267339

智能推荐

CSUST OJ 2020_oj 有x个瓶盖-程序员宅基地

文章浏览阅读237次。这题啊,傻逼题首先因为想看看大家的思维和写法,并没有针对题目进行数据加强,所以基本上怎么暴力写都能过其实这题是由一个很经典的题目扩展而来的。即:你有a个瓶盖,b个瓶盖能换一瓶可乐,问你最多能喝多少瓶可乐。但这题稍微负责一些,因为瓶子和瓶盖换的新可乐,有一个瓶盖和瓶子,所以会相互影响。所以我们每次算出瓶子和瓶盖分别能换多少可乐,然后再更新瓶子和瓶盖的数量就行了。所以针对数据氛围,暴力就..._oj 有x个瓶盖

Vue项目搭建常用的配置文件,request.js和vue.config.js_interceptors.request.use 没有config-程序员宅基地

文章浏览阅读6.4w次,点赞248次,收藏1k次。笔记_interceptors.request.use 没有config

OpenShift 4.5 新特性 - 创建任务和定时任务_openshift cronjob-程序员宅基地

文章浏览阅读1.1k次。文章目录通过YAML创建创建Job创建CronJob使用命令创建Job创建CronJob在Kubernetes中分贝使用Job和CronJob实现一次性运行的任务和定时运行的的任务,他们分别被Kubernetes的JobController和CronJobController控制器所控制,而这些任务都是通过Pod运行的。在创建Job和CronJob对象的时候,既可以使用定义对象的YAML文件,还可使用命令直接创建。需要注意的是,从OpenShift 4.5开始,在使用oc命令创建Job和CronJob对_openshift cronjob

前端js实现canves画布中拖拽、放大、缩小、旋转图片和文字,设置背景图片,导出_fabric.js 截取固定大小图片-程序员宅基地

文章浏览阅读2.7k次。最近在研究canves,想实现一个可以在画布中操作上传的内容,不经意间发现了个插件Fabric.js。Fabric.js 是一个强大的H5 canvas框架,在原生canvas之上提供了交互式对象模型,通过简洁的api就可以在画布上进行丰富的操作。image。_fabric.js 截取固定大小图片

iOS 音频的录制、播放及音频文件管理_updatemeters-程序员宅基地

文章浏览阅读2.1w次,点赞2次,收藏6次。音频会话音效播放音乐播放音频录制音频管理音频队列服务参考地址_updatemeters

深入理解机械臂动力学建模_机械臂 组合体惯量法-程序员宅基地

文章浏览阅读1.8w次,点赞4次,收藏87次。A刚性机械臂机械臂建模是机械臂控制的基础,控制效果的好坏很大程度上决定于所建立的动力学模型的准确性。目前对刚性机械臂的动力学建模方法较多,理论较为成熟。而对于柔性空间机械臂的精确建模尚处在研究阶段。 表格1 刚体动力学建模原理..._机械臂 组合体惯量法

随便推点

mysql5.7.20出现The server time zone value '�й���׼ʱ��' is unrecogni。。。。的解决办法-程序员宅基地

文章浏览阅读1.3w次,点赞4次,收藏12次。java.sql.SQLException: The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configu...

GitLab配置ssh-key_gitlab更新ssh-key-程序员宅基地

文章浏览阅读1.9k次。1 背景当前很多公司都选择git作为代码版本控制工具,然后自己公司搭建私有的gitlab来管理代码,我们在clone代码的时候可以选择http协议,当然我们亦可以选择ssh协议来拉取代码。但是网上很少找到如何用git客户端生成ssh key,然后配置在gitlab,我当时在做的时候苦于摸索,后来终于找到了解决方案,那么本文,我们就来聊一聊如何本地git客户端生成ssh key,然后配置在gitlab里,而后使用ssh协议进行提交和拉取git远程仓库的代码。2 解决方案打开本地git bash,使用_gitlab更新ssh-key

计算机网络考试试题库-期末考试题库含答案_某公司 testa 有一个总部和三个下属工厂。总部有 4 个局域网,其 中 lan2-lan4 都-程序员宅基地

文章浏览阅读1.2w次,点赞33次,收藏332次。一、选择题(第一章 1-10;第二章 11-20;第三章21-35;第四章36-60 ;第五章 61-73道;第六章 74-84道;第七章85-90;第九章91-95;第十章96-100)1.下列四项内容中,不属于Internet(因特网)基本功能是____D____。A.电子邮件 B.文件传输 C.远程登录 D.实时监测控制2.Internet是建立在____C_____协议集上的国际互联网络。 A.IPX B.NetBEUI C.TCP/IP _某公司 testa 有一个总部和三个下属工厂。总部有 4 个局域网,其 中 lan2-lan4 都

高通平台GPU动态调频DCVS . 篇1 . Interface_高通 gpu 限频 /sys/class/kgsl/kgsl-3d0/max_pwrlevel-程序员宅基地

文章浏览阅读9.4k次,点赞13次,收藏43次。高通平台的GPU内核驱动架构趋于稳定,代码和接口都具备通用性,故分析整理出来以供快速参考高通平台GPU内核驱动框架全称是 Kernel-Graphics-Support-Layer KGSL1. KGSL kernel interfacekgsl驱动所暴露出来的GPU相关常规控制接口位于 /sys/class/kgsl/kgsl-3d0 路径下/sys/class/kgsl/kgsl-3d..._高通 gpu 限频 /sys/class/kgsl/kgsl-3d0/max_pwrlevel

网络安全系列-XI: 主流网络协议介绍_xiip-程序员宅基地

文章浏览阅读4.2k次。本文针对主流的网络协议进行介绍_xiip

正则表达式-实数_实数正则判断-程序员宅基地

文章浏览阅读3k次。整数整数包括:0,正整数,负整数00的正则:^0$正整数正整数(必须为1-9开头,后面[0-9]0个或多个)的正则:^[1-9]\d*$负整数负整数(正整数前加"-"):^\-[1-9]\d*$0,正整数和负整数合并起来就是整数:^-?[1-9]\d*|0$小数(这里说的时末尾可以为0的小数)小数就是整数加上小数点再加上1个或多个[0-9],即^(\-?[1-9]\d*|0)\.\d+$"|"会作用于全部范围,所以要加括号。(这里说的时末尾不为0的小数)小数就是整_实数正则判断