[Matlab] Matlab GUI and simulink mixed call and parameter transfer

tags: matlab  simulink

Date: 2017/6/7

Author: Soaringlee


1. Reference

 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

 

2. Call Simlink module (.xls, .mdl) in Matlab GUI

options = simset('SrcWorkspace','current');% set matlab and simulink to share the same workspace

 open_system('arm_mod');% open model arm_mod.mdl
 sim('arm_mod',[ ],options);% The first parameter is the model name, the second parameter contains the start and end time, and the third parameter is the configuration obtained by this simset

 

3. Close the current matlab gui

close(handles.output);

 

4. Use functions to pass parameters across spaces

set_param('model name/module name', attribute 1, attribute 2, attribute 3,...);

 get_param('model name/module name', ObjectParameters)

 

5. Clear the axes image in the GUI

 axes(handles.axes1);

 cla reset;

 

6. Case analysis

Description: Call the simulink module PV_guangzhaobutong.mdl in FirstSimulinkGUI.m, the method is as follows:

options = simset('SrcWorkspace','current');
sim('PV_guangzhaobutong.mdl',[],options);

How to get and set the parameters of the module in the simulink module:

set_param('model name/module name', attribute 1, attribute 2, attribute 3,...);

 get_param('model name/module name', ObjectParameters)

There is no code for getting and setting parameters in the current instance.

The specific matlab code is as follows:

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)% simulation model of output characteristics of the same photovoltaic cell temperature
% 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 curve');

axes(handles.axes2);
plot(V,P),hold on;
axis([0 25 0 100]);
xlabel('V'),ylabel('P');
 title('P-V curve');


% --- Executes on button press in pushbutton2.
 function pushbutton2_Callback(hObject, eventdata, handles) %Return to the main interface
% 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)% description
% 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 ='This model simulates the output characteristics of photovoltaic cells that change with the increase of light intensity at the same temperature. In this simulation, the module can be modified as a light intensity parameter module. Set different values ​​to get the output U-I and U-P characteristic curves of photovoltaic cells under the same temperature and different light conditions. ';
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 simulation is as follows:


THE END!

 

 

 

Intelligent Recommendation

Parameter limited MPC and Matlab/Simulink/C++ implementation

Write in front The prediction time domain length Np should contain the main dynamic part of the object, the smaller the faster, the more unstable, the larger, the lower the real-time, and the slower t...

Simulink code generation: call Matlab function

This paper studies the method of calling Matlab function in Simulink model. Article Directory 1 Matlab Function module 2 Modeling and code generation 3 Data management in Matlab Function 3.1 Associate...

Use C # to call Matlab engines to control Simulink

Use C # to call Matlab engines to control Simulink 1.c # call MATLAB engine Add a MATLAB reference in C # Use the MATLAB engine Everything can use the MATLAB operation of Simulink instructions to oper...

Coursework ------ Matlab creates a GUI interface combined with Simulink simulation

Take the simplest single-phase half-wave rectifier circuit as an example   Enter Matlab, the beginning is only the command line Input The following interface appears Save as a hook, and name it, ...

Matlab GUI programming skills (4): data transmission between files and simulink

Matlab GUI programming skills series articles index: Matlab GUI programming skills (1): How to make the interface of the GUI editor run in the middle Matlab GUI programming skills (2): function struct...

More Recommendation

VS2013 and MATLAB call each other mixed programming

Visual Studio and MATLAB mixed programming, there are two methods: 1 MATLAB calls C program; 2 VS calls MATLAB (all VS is currently seen, other compilers such as codeblocks, or do not provide this fun...

VS and Matlab mixed programming-call matlab.dll

I use VS2010 (32-bit) and Matlab2014a (64-bit) 1. Write a simple addition function in Matlab, for example Save as add.m file. Enter the mex -setup command in the command window and select "mex -s...

Matlab GUI, transfer data between forms

(Code: Main window 2\main1.m,Child window  2\ch1.m  ) Main window: Child window:...

Vc call matlab exported dll, achieve vc mixed programming with matlab

VctransfermatlabExporteddll,achievevcversusmatlabHybrid Programming Under the purpose of writing this blog is trying to work some time ago of the transfer, so that those who take over the project peop...

Matlab and C / C ++ Matlab mixed programming call C functions

Matlab and C / C ++ mixed programming There are many ways, are suitable for different situations. Program body using Matlab, it is time consuming to increase the efficiency of the special function rew...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top