tutorial 03 plotting in simulink - ihaltas.com · tutorial 3 - 13 exporting data to .mat file this...

9
Tutorial 3 - 1 The University of New Brunswick Department of Electrical and Computer Engineering Fredericton, NB, E3B 5A3 Canada Tutorial 3 - 2 Using Matlab/Simulink Using Matlab/Simulink

Upload: others

Post on 08-Aug-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Tutorial 03 Plotting in Simulink - ihaltas.com · Tutorial 3 - 13 Exporting Data to .MAT file This is the file (p1.mat), which contains the exported data. The first row of the exported

Tutorial 3 - 1

The University of New BrunswickDepartment of Electrical and Computer Engineering

Fredericton, NB, E3B 5A3 Canada

Tutorial 3 - 2

Using Matlab/Simulink Using Matlab/Simulink

Page 2: Tutorial 03 Plotting in Simulink - ihaltas.com · Tutorial 3 - 13 Exporting Data to .MAT file This is the file (p1.mat), which contains the exported data. The first row of the exported

Tutorial 3 - 3

Matlab Main Window

Command window

Directory listing

Tutorial 3 - 4

Matlab Main Window

Type simulink on command window andhit <enter>

Or double click the file to open

Page 3: Tutorial 03 Plotting in Simulink - ihaltas.com · Tutorial 3 - 13 Exporting Data to .MAT file This is the file (p1.mat), which contains the exported data. The first row of the exported

Tutorial 3 - 5

Simulink Library Browser

Select NEW to start a new

project

Tutorial 3 - 6

Starting a new project

Drag and drop

Page 4: Tutorial 03 Plotting in Simulink - ihaltas.com · Tutorial 3 - 13 Exporting Data to .MAT file This is the file (p1.mat), which contains the exported data. The first row of the exported

Tutorial 3 - 7

Connecting Blocks

Select the firstblock, hold <Ctrl> key down andclick the targetblock. This goeswith single inputblocks. Or thefirst input of theblocks withmultiple inputs.

Hold left mouse button on the connection point of one of the blocks anddrag it to the connection point of the other block then relase the mouse

Tutorial 3 - 8

Changing Block Parameters

Double click the blocks to edit their parameters.

Page 5: Tutorial 03 Plotting in Simulink - ihaltas.com · Tutorial 3 - 13 Exporting Data to .MAT file This is the file (p1.mat), which contains the exported data. The first row of the exported

Tutorial 3 - 9

Changing Block Parameters

Move mouse over a block and hold theright button down to get more featuresfor the block.

Tutorial 3 - 10

Displaying and Printing Graphs

You can display the responses using scope window. However, scopewindow is not good to be used in reports. However, you cannot edit the axis labels. Besides, the dark background is not good for printing.

Page 6: Tutorial 03 Plotting in Simulink - ihaltas.com · Tutorial 3 - 13 Exporting Data to .MAT file This is the file (p1.mat), which contains the exported data. The first row of the exported

Tutorial 3 - 11

Exporting Data to .MAT file

From the Simulink Library Sinks, select theblock To File

Drag the block To Fileon to your work project

You can export your data toMatlab workspace or to an .m file and then plot it for thereports.

Tutorial 3 - 12

Exporting Data to .MAT file

Double click each To File block andchange file name and variable name tosuit your model system.

Page 7: Tutorial 03 Plotting in Simulink - ihaltas.com · Tutorial 3 - 13 Exporting Data to .MAT file This is the file (p1.mat), which contains the exported data. The first row of the exported

Tutorial 3 - 13

Exporting Data to .MAT file

This is the file (p1.mat), which contains theexported data.

The first row of the exporteddata is the simulation time in seconds and the second rowis the variable.

The variable stored here is PP1.

The file p1.mat is saved into your working directory. This file is then called from either Matlab Command Window or from an .m file.

Tutorial 3 - 14

Using .MAT files in MATLAB

Load .mat file content to workspace

Shows the variables currently in memory

The variable in memory is PP1

Get transpose of PP1 as D so that you willhave 2 columns data file instead of 2 rows

Get time t and variable y1 as 2 separatesingle column vectors for plotting.

Plot y vs. t.

Page 8: Tutorial 03 Plotting in Simulink - ihaltas.com · Tutorial 3 - 13 Exporting Data to .MAT file This is the file (p1.mat), which contains the exported data. The first row of the exported

Tutorial 3 - 15

Using .MAT files in MATLAB

Copy figure to clipboard. Then fromclipboard to your document as on the left..

Tutorial 3 - 16

Using .MAT files in MATLAB

This is a sample for a good grapgh in a document file.

Page 9: Tutorial 03 Plotting in Simulink - ihaltas.com · Tutorial 3 - 13 Exporting Data to .MAT file This is the file (p1.mat), which contains the exported data. The first row of the exported

Tutorial 3 - 17

Using .MAT files in .m files

You can download this.m file from thecourse site.

Tutorial 3 - 18

Printer Friendly Plots

Save ink or toner.