GUI数据传递userdata
来源:互联网 发布:赛车竞猜源码 编辑:程序博客网 时间:2024/04/29 06:28
function varargout = lsss(varargin)% LSSS MATLAB code for lsss.fig% LSSS, by itself, creates a new LSSS or raises the existing% singleton*.%% H = LSSS returns the handle to a new LSSS or the handle to% the existing singleton*.%% LSSS('CALLBACK',hObject,eventData,handles,...) calls the local% function named CALLBACK in LSSS.M with the given input arguments.%% LSSS('Property','Value',...) creates a new LSSS or raises the% existing singleton*. Starting from the left, property value pairs are% applied to the GUI before lsss_OpeningFcn gets called. An% unrecognized property name or invalid value makes property application% stop. All inputs are passed to lsss_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 lsss% Last Modified by GUIDE v2.5 27-Nov-2013 10:44:06% Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @lsss_OpeningFcn, ... 'gui_OutputFcn', @lsss_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []);if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1});endif 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 lsss is made visible.function lsss_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 lsss (see VARARGIN)% Choose default command line output for lssshandles.output = hObject;% Update handles structureguidata(hObject, handles);% UIWAIT makes lsss wait for user response (see UIRESUME)% uiwait(handles.figure1);% --- Outputs from this function are returned to the command line.function varargout = lsss_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 structurevarargout{1} = handles.output;xlabel('t')ylabel('y')% --- 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)tspan = [0 get(handles.time, 'Userdata')]; %这里就是用Userdata传递数据y0 = [get(handles.y0, 'Userdata');get(handles.dy0, 'Userdata')];options = odeset('RelTol', 1e-4, 'AbsTol', [1e-4 1e-4]);[t, y] = ode45(@fun, tspan, y0, options);plot(t, y(:, 1), '-')syms y(t)Dy = diff(y);fu = dsolve(diff(y, 2) == -6*cos(2*t)+3*sin(t)+t-11.5, y(0) == y0(1), Dy(0) == y0(1));t2 = 0:tspan(2)/100:tspan(2);yAna = subs(fu, t, t2);hold onplot(t2, yAna, 'r-')legend('numerical solution', 'analytical solution')title('y=-6*cos(2*t)+3*sin(t)+t-11.5')hold offfunction dy = fun(t, y) dy = zeros(2, 1); dy(1) = y(2); dy(2) = -6*cos(2*t)+3*sin(t)+t-11.5;function y0_Callback(hObject, eventdata, handles)% hObject handle to y0 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of y0 as text% str2double(get(hObject,'String')) returns contents of y0 as a doubley0 = str2double(get(hObject, 'String'));set(hObject, 'UserData', y0)% --- Executes during object creation, after setting all properties.function y0_CreateFcn(hObject, eventdata, handles)% hObject handle to y0 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');endy0 = str2double(get(hObject, 'String'));set(hObject, 'UserData', y0)function dy0_Callback(hObject, eventdata, handles)% hObject handle to dy0 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of dy0 as text% str2double(get(hObject,'String')) returns contents of dy0 as a doubledy0 = str2double(get(hObject, 'String'));set(hObject, 'UserData', dy0)% --- Executes during object creation, after setting all properties.function dy0_CreateFcn(hObject, eventdata, handles)% hObject handle to dy0 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');enddy0 = str2double(get(hObject, 'String'));set(hObject, 'UserData', dy0)% --- Executes on slider movement.function time_Callback(hObject, eventdata, handles)% hObject handle to time (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'Value') returns position of slider% get(hObject,'Min') and get(hObject,'Max') to determine range of slidertspan = get(hObject,'Value');set(hObject, 'UserData', tspan);% --- Executes during object creation, after setting all properties.function time_CreateFcn(hObject, eventdata, handles)% hObject handle to time (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: slider controls usually have a light gray background.if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor',[.9 .9 .9]);endtspan = get(hObject,'Value');set(hObject, 'UserData', tspan);
结果:
参考:
【1】GUI间的数据传递机制http://blog.csdn.net/dfd1r/article/details/6302063
- GUI数据传递userdata
- 【matlab】GUI 数据用Userdata的传递使用
- MatLab GUI 数据传递
- MatLab GUI 数据传递
- MatLab GUI 数据传递
- Matlab------------GUI编程:gui编程数据传递
- MATLAB GUI 数据传递方法
- 传递userdata到lua
- GUI间的数据传递机制
- MATLAB GUI界面之间的数据传递
- Matlab GUI 界面间数据的传递
- gui数据传递的方式讨论汇总
- GUI数据传递01-全局变量法
- matlab-两个gui的数据传递
- MatLab GUI 学习笔记-数据传递
- Matlab GUI,窗体之间传递数据
- userData
- Userdata
- iOS 关于音频开发
- hive与hbase整合
- Linux Support for ARM LPAE 分析
- 美国轰炸机进入我国领域
- gson(json转对象和对象转json的方法)
- GUI数据传递userdata
- 机器学习中的算法(2)-支持向量机(SVM)基础
- Eclipse打JAR包,插件FatJar安装与使用
- CXF+Spring+Tomcat简明示例
- Android,关于设备独立像素(dip/dp),关于机型屏幕适配
- 关于SD卡和FAT32在lpc3250中的移植
- 随机化文件行的顺序
- 哈弗曼树的构造
- mahout学习