Top Banner

of 17

Files and Simulink

Apr 04, 2018

Download

Documents

Khghost Mass
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • 7/30/2019 Files and Simulink

    1/17

    1

    Load

    Load workspace variables from disk

    Syntax

    Save

    Save workspace variables on disk

    Graphical Interface

    As an alternative to the save function, select Save Workspace As from the File menu

    in the MATLAB desktop, or use the Workspace browser.

    Syntax

    Open

    Open files based on extension

    Syntax

    Description

    open('name') opens the object specified by the string name. The specific action

    taken upon opening depends on the type of object specified by name.

    EngEngEngEng \\\\ Hadeer SobhyHadeer SobhyHadeer SobhyHadeer Sobhy

  • 7/30/2019 Files and Simulink

    2/17

    2

    Opening a MAT-File

    EngEngEngEng \\\\ Hadeer SobhyHadeer SobhyHadeer SobhyHadeer Sobhy

  • 7/30/2019 Files and Simulink

    3/17

    3

    Fopen

    Open a file or obtain information about open files

    Syntax

    Description

    -fid = fopen(filename) opens the file filename for read access. (On PCs, fopenopens files for binary read access.)

    - fidis a scalar MATLAB integer, called a file identifier. You use the fid as the firstargument to other file input/output routines.

    If fopen cannot open the file, it returns -1.

    - fid = fopen(filename, mode) opens the file filename in the specified mode. Themode argument can be any of the following:

    Fclose

    Close one or more open files

    Syntax

    Description

    - status = fclose(fid) closes the specified file if it is open, returning 0 if successfuland -1 if unsuccessful.

    EngEngEngEng \\\\ Hadeer SobhyHadeer SobhyHadeer SobhyHadeer Sobhy

  • 7/30/2019 Files and Simulink

    4/17

    4

    Argument fid is a file identifier associated with an open file. (Seefopen for a

    complete description of fid).

    If fid does not represent an open file, or if it is equal to 0, 1, or 2, thenfclose throws

    an error.

    - status = fclose('all') closes all open files (except standard input, output, and

    error), returning 0 if successful and -1 if unsuccessful.

    Fprintf

    Write formatted data to file

    Syntax

    Description- count = fprintf(fid,format,A,...) formats the data in the real part of matrix A(and in any additional matrix arguments) under control of the specified format

    string, and writes it to the file associated with file identifier fid. fprintf returns a

    count of the number of bytes written.

    EngEngEngEng \\\\ Hadeer SobhyHadeer SobhyHadeer SobhyHadeer Sobhy

  • 7/30/2019 Files and Simulink

    5/17

    5

    This table lists the escape character sequences you use to specify nonprinting

    characters in a format specification.

    Fread

    Read binary data from file

    Syntax

    Description

    - A = fread(fid) reads data in binary format from the file specified by fid intomatrix A.

    - Open the file usingfopen before callingfread. The fid argument is the integer file

    identifier obtained from thefopen operation.

    - MATLAB reads the file from beginning to end, and then positions the file pointer

    at the end of the file.

    EngEngEngEng \\\\ Hadeer SobhyHadeer SobhyHadeer SobhyHadeer Sobhy

  • 7/30/2019 Files and Simulink

    6/17

    6

    Specifying Precision

    Any of the strings in the following table, either the MATLAB version or their C or

    FORTRAN equivalent, can be used for precision. If precision is not specified,

    MATLAB uses the default, which is 'uchar'.

    The following platform-dependent formats are also supported, but they are not

    guaranteed to be the same size on all platforms.

    EngEngEngEng \\\\ Hadeer SobhyHadeer SobhyHadeer SobhyHadeer Sobhy

  • 7/30/2019 Files and Simulink

    7/17

    7

    Examples:

    Example 1

    The file alphabet.txt contains the 26 letters of the English alphabet, all capitalized.

    Open the file for read access withfopen, and read the first five elements into outputc. Because a precision has not been specified, MATLAB uses the default precision of

    uchar, and the output is numeric:

    This time, specify that you want each element read as an unsigned 8-bit integer and

    output as a character. (Using a precision of 'char=>char' or '*char' will produce the

    same result):

    When you leave out the optional count argument, MATLAB reads the file to the

    end, A through Z:

    Thefopen function positions the file pointer at the start of the file. So the firstfread

    in this example reads the first five elements in the file, and then repositions the file

    pointer at the beginning of the next element. For this reason, the nextfreadpicks up

    where the previousfreadleft off, at the character

    EnEnEnEngggg \\\\ Hadeer SobhyHadeer SobhyHadeer SobhyHadeer Sobhy

  • 7/30/2019 Files and Simulink

    8/17

    8

    Skip two elements between each read by specifying a skip argument of 2:

    Fwrite

    Write binary data to a file

    Syntax

    Description

    - count = fwrite(fid,A,precision) writes the elements of matrix A to the specifiedfile, translating MATLAB values to the specified precision.

    - The data is written to the file in column order, and a count is kept of the number of

    elements written successfully.

    Examples:

    EngEngEngEng \\\\ Hadeer SobhyHadeer SobhyHadeer SobhyHadeer Sobhy

  • 7/30/2019 Files and Simulink

    9/17

    9

    Programs:

    Reading and Writing wave files

    Reading and Writing text files

    EngEngEngEng \\\\ Hadeer SobhyHadeer SobhyHadeer SobhyHadeer Sobhy

  • 7/30/2019 Files and Simulink

    10/17

    10

    To open SIMULINK at MATLAB

    Then ..

    EngEngEngEng \\\\ Hadeer SobhyHadeer SobhyHadeer SobhyHadeer Sobhy

  • 7/30/2019 Files and Simulink

    11/17

    11

    OR .

    Then ..

    EngEngEngEng \\\\ Hadeer SobhyHadeer SobhyHadeer SobhyHadeer Sobhy

  • 7/30/2019 Files and Simulink

    12/17

  • 7/30/2019 Files and Simulink

    13/17

    13

    Now lets try something a little bit more complicated.First, build the following system (you can find the Clock module in the Sinks category.The Trigonometric Function and Sum modules reside in theMath category):

    Output on Time Scope

    Now, lets see if the derivative is really a cosine. Build the following system (theDerivative module is located in the Continuous category):

    EngEngEngEng \\\\ Hadeer SobhyHadeer SobhyHadeer SobhyHadeer Sobhy

  • 7/30/2019 Files and Simulink

    14/17

    14

    We can see that this is indeed a cosine, but something is wrong at the beginning.

    EngEngEngEng \\\\ Hadeer SobhyHadeer SobhyHadeer SobhyHadeer Sobhy

  • 7/30/2019 Files and Simulink

    15/17

    15

    1.Low Pass Filter2.High Pass Filter3.Band Pass Filter4.Band Stop Filter5.Resonator Filter6.Notch Filter

    EngEngEngEng \\\\ Hadeer SobhyHadeer SobhyHadeer SobhyHadeer Sobhy

  • 7/30/2019 Files and Simulink

    16/17

    16

    Low Pass Filter

    High Pass Filter

    Band Pass Filter

    Notch Filter

    To get filter on simulink as follow:

    Signal Processing Blackest >>Filtering>>Filter Design>>Digital Filter Design

    EngEngEngEng \\\\ Hadeer SobhyHadeer SobhyHadeer SobhyHadeer Sobhy

  • 7/30/2019 Files and Simulink

    17/17

    17

    EngEngEngEng \\\\ Hadeer SobhyHadeer SobhyHadeer SobhyHadeer Sobhy