About Site Map Submit Contact Us Log in | Create an account
Create an account Log In
Average Rating
User Rating:
Visitors Rating:
My rating:

Write review
  • Last update: 5 years ago
  • Total downloads: 43
  • Operating system: Linux, Mac OS X, Win All, BSD, Solaris
  • Publisher: Jim Hunziker
See full specifications

scripts default iconClosures in the MATLAB Language (Scripts) Publisher's description

Sometimes in MATLAB, a programmer might want to write functions that maintain state without exposing that state to the global workspace.

Sometimes in MATLAB, a programmer might want to write functions that maintain state without exposing that state to the global workspace.

A closure is a concept in computer science that describes the execution of a function that has privately captured variables from an enclosing scope. Through nested functions and function handles, a user can create closures in MATLAB.

By privately capturing variables, a closure can help the programmer avoid maintaining global state variables and write more modular code.

This simple example shows how to write a function that takes an argument n and returns another function. This returned function can be called multiple times, returning n plus the number of times the function has been called previously.

Here is another useful application of closures. Suppose you have to do an operation that needs to work on every item in a sequence. There are many many items, and you can't afford the space to calculate them all at once, store them, and do the operation on them in a loop.

But you have plenty of time and CPU power. You can make a function like makeIncrementer (in the attached example) that remembers where it was in the sequence and generate each item on demand.

Learning to use closures can make your MATLAB routines smaller and your code more modular.

System Requirements:

MATLAB 7.0.4 (R14SP2)
Program Release Status: New Release
Program Install Support: Install and Uninstall

Closures in the MATLAB Language (Scripts) Tags:

Click on a tag to find related softwares

Is Closures in the MATLAB Language (Scripts) your software?

Manage your software

Most Popular

scripts default icon ASK, OOK, FSK, BPSK, QPSK, 8PSK modulation 1.1
ASK, OOK, FSK, BPSK, QPSK, 8PSK modulation contain several functions for digital modulation simulation
scripts default icon Simulink Communication Labs 1.1
Simulink Communication Labs allows you to learn communication systems in greater depth.
scripts default icon M-QAM modulation and demodulation 1.1
M-QAM modulation and demodulation is the QAM modulation and demodulation tech.
scripts default icon LZW Compression/Decompression 1.1
LZW Compression/Decompression - Updated LZW compressor and decompressor with reasonable performance
scripts default icon InSPIRE utility to plot a 2D displacement field (Scripts) 1.0
This program plots the deformation field (displace vectors) contained in vector.txt.