http://www.doc88.com/p-2854357902240.html
http://www.ilovematlab.cn/thread-136678-1-1.html
http://blog.sina.com.cn/s/blog_4d7a8dc101016id5.html
https://stackoverflow.com/questions/20865463/matlab-simulink-graph-plotting
http://proteus261040013.blog.163.com/blog/static/1186118842010111475911982/
https://stackoverflow.com/questions/20865463/matlab-simulink-graph-plotting
options = simset('SrcWorkspace','current'); %设置matlab和simulink共用相同的工作空间
open_system('arm_mod'); %打开模型arm_mod.mdl
sim('arm_mod',[ ],options); %第一个参数是模型名,第二个参数包含开始和结束时间,第三个参数是这个simset得到的配置
close(handles.output);
set_param('模型名/模块名',属性1,属性2,属性3,......);
get_param('模型名/模块名',ObjectParameters)
axes(handles.axes1);
cla reset;
说明:在FirstSimulinkGUI.m中调用simulink模块PV_guangzhaobutong.mdl,方法如下:
options = simset('SrcWorkspace','current');
sim('PV_guangzhaobutong.mdl',[],options);
获取和设置simulink模块中模块的参数的方法:
set_param('模型名/模块名',属性1,属性2,属性3,......);
get_param('模型名/模块名',ObjectParameters)
当前实例中没有获取和设置参数的代码。
具体matlab代码如下:
function varargout = FirstSimlinkGUI(varargin)
% FIRSTSIMLINKGUI MATLAB code for FirstSimlinkGUI.fig
% FIRSTSIMLINKGUI, by itself, creates a new FIRSTSIMLINKGUI or raises the existing
% singleton*.
%
% H = FIRSTSIMLINKGUI returns the handle to a new FIRSTSIMLINKGUI or the handle to
% the existing singleton*.
%
% FIRSTSIMLINKGUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in FIRSTSIMLINKGUI.M with the given input arguments.
%
% FIRSTSIMLINKGUI('Property','Value',...) creates a new FIRSTSIMLINKGUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before FirstSimlinkGUI_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to FirstSimlinkGUI_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 FirstSimlinkGUI
% Last Modified by GUIDE v2.5 07-Jun-2017 10:28:56
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @FirstSimlinkGUI_OpeningFcn, ...
'gui_OutputFcn', @FirstSimlinkGUI_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 FirstSimlinkGUI is made visible.
function FirstSimlinkGUI_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 FirstSimlinkGUI (see VARARGIN)
% Choose default command line output for FirstSimlinkGUI
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes FirstSimlinkGUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = FirstSimlinkGUI_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)
options = simset('SrcWorkspace','current');
sim('PV_guangzhaobutong.mdl',[],options);
axes(handles.axes1);
plot(V,I),hold on
axis([0 25 0 6]);
xlabel('V'),ylabel('I');
title('I-V曲线');
axes(handles.axes2);
plot(V,P),hold on;
axis([0 25 0 100]);
xlabel('V'),ylabel('P');
title('P-V曲线');
% --- 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)
close(handles.output);
run('StartSimlinkGUI');
% --- 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)
tips = '此模型是仿真在相同温度下光伏电池随着光照强度的增加而改变的输出特性。本次仿真可修改模块为光照强度参数模块,设置不同的值即可运行得到相同温度不同光照条件下的光伏电池输出U-I和U-P特性曲线。';
set(handles.edit1,'string',tips);
guidata(hObject,handles);
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (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 edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (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');
end
仿真结果如下:
THE END!