8000 GitHub - andreassommer/mmtools: Miscellaneous Matlab Tools
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

andreassommer/mmtools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mmtools - Miscellaneous Matlab Tools

A collection of free and open source Matlab tools.

Andreas Sommer, 2010-2024
E-Mail: code@andreas-sommer.eu

 

IMPORTANT: Mathworks File Exchange renders Github links in a wrong way (August 2024).

--> Open this README on Github <--

List of Tools

Tools marked with ⭐ might be especially worth a look.

Documentation is provided inside the code and thus available using Matlab's help system via help and doc.



ADLER32 [see code]

Computes the Adler32 hash of a given char array.

Return to list of tools

condSet [see code]

Conditionally sets values in (cell) array/matrix/vector. Can also evaluate function on the elements of a given (cell) array/matrix/vector at places where the specified condition is true or false.

% EXAMPLE CALLS:
M = magic(5); R = -rand(5);         % matrices for testing
z = condSet(M>10, 1, 5)             % --> matrix of size(M) with 1 where M>10, and 5 otherwise
z = condSet(M>10, 1, 5, {})         % --> cell array of size(M) with 1 where M>10, and 5 otherwise
z = condSet(M>10, '2BIG')           % --> cell array of size(M) with '2BIG' where M>10
z = condSet(M>10, 10, M)            % --> copy of M with value 10 where M>10
z = condSet(M>10, @(x) x^2, -1, M)  % --> copy of M with squared entries where M>10, and -1 otherwise
z = condSet(M>10, R, {}, M)         % --> copy of M with values from R where M>10

Return to list of tools

DEBUGME [see code]

Debug helper for changed valued. It transparently returns the new value while displaying as message about that.
The message can be freely configurated. Helpful to not forget to undo test changes.
var = sin(x + 0.5); -- original code to be modified
var = sin(x + DEBUGME(1.5)); -- delivers value 1.5 and displays standard debug marker message
var = sin(x + DEBUGME(1.5, 'SIN offset changed to %g')); -- delivers 1.5 and displays individual message

Special command initiated with # allow configuration of debug output.

  • The printer for the debug message can be chosen via special command #printer and set to any function handle that can parse fprintf like input, e.g. @fprintf or @warning
  • Quick reset can be done using special command #reset
  • See code for details.

Return to list of tools

execWSL [see code]

Executes a command in WSL (Windows Subsystem for Linux).
Distribution can be chosen. Dryrun and echoing supported.

Return to list of tools

findfield [see code]

In a struct with many (several hundreds) of fields, finding the correct field name can be cumbersome. The findfield() function allows to search for fieldnames by string patters or regular expressions, and also provides information if an exact match is found.

Return to list of tools

findFirstGreater [see code]

Firns first entry in array that is greater than a specified value. Optionally starts search at given index.

Return to list of tools

hornereval [see code]

Evaluation of 1d polynomials using Horner's scheme.

Return to list of tools

hornereval2D [see code]

Evaluation of 2d polynomials using Horner's scheme.

Return to list of tools

getCaller [see code]

Retrieve calling function, optionally with file name and line number. Relies on Matlab's dbstack.

Return to list of tools

getParentFigure [see code]

Retrieve the handle of the figure that contains the specified graphics handle.

Return to list of tools

getWorkspaceVariable [see code]

Retrieve a variable from other workspace (base or caller), with optional not-found value and error signaling capability.

Return to list of tools

integrate_with_restarts⭐ [see code]

A Matlab tool for integration of switched ODEs, with implicit (state-dependent) model and state changes.
Only integration is supported.
The tool IFDIFF is much more sophisticated. It generates switching functions automatically from existing code with IF statements and can also compute forward sensitivities.

Return to list of tools

isfigure [see code]

Queries if specified handle refers to a (valid) figure.

Return to list of tools

istext [see code]

Checks if specified object is a char array or a string

Return to list of tools

makeClosure [see code]

Generates a closure to mimick pass-by-reference style of programming.

Return to list of tools

makeMessage [see code]

Display or generate message and prepone the calling function. makeMessage is a wrapper around Matlab's *printf functions, but accepts also other printer functions that follow the sprintf or fprintf API.

Return to list of tools

msession⭐ [see code]

Stores a whole Matlab work session in a file, and restores it upon request. The user can select what to be stored:

  • open files
  • main work space variables
  • global variables

Return to list of tools

optionlists⭐ [see code]

Matlab tools for handling name-value pairs, especially in function calls.

  • querying arguments by name: olGetOption
  • checking for present arguments: olHasOption
  • generation of option lists: olSetOption
  • removing from option lists: olRemoveOption
  • rename existing options: olRenameOption
  • checking validity: olIsOptionlist
  • checking validity with assertion: olAssertOptionlist
  • retrieving list of all names: olCollectOptionNames
  • retrieving list of all values: olCollectOptionValues
  • warn upon unprocessed arguments: olWarnIfNotEmpty

Documentation

For details, see, help olGetOption, etc.

Example

Call:

  val = f(a,b,'name','test','age',35,'numbers',{1,7,2})

Function code:

function val = f(a,b,varargin)
    % a and b are normal position-dependent arguments.
    % Further arguments are (usually) optional and initialized by default values.
  
    % Set default values
    name    = 'defaultname';
    age     = 0;
    numbers = {1,2,3,4,5};
    
    % Query optional arguments:
    if olHasOption(varargin, 'age'    ),     age = olGetOption(varargin, 'age'    );  end
    if olHasOption(varargin, 'numbers'), numbers = olGetOption(varargin, 'numbers');  end

    % Alternatively, default arguments can be specified in olGetOption directly if key is not found:
    name = olGetOption(varargin, 'name', '[UNKNOWN-PERSON]');
   
    % Program code 
    % ...
end    

The syntax [value, remainingOptions] = olGetOption(options, key) can be used to remove key from the optionlist. This is useful to check if there are some options left after processing using olWarnIfNotEmpty.

Return to list of tools

pointpicker [see code]

This tool is intended to collect point coordinated from a matlab figure, and pick and collect points by clicking. Register to the current axis using pointpicker(gca()).

The pointpicker may be registered to multiple figures/axes, but only collects points from the currently active one. By pressing key 'a' while in the registered axis, the mouse changes to a crosshairs and multiple points can be collected; the last one picked can be deleted by pressing 'd'. Collection is ended by pressing 'x'. Collected points may be retrieved into a variable by points = pointpicker('#GET') or saved to file.

Return to list of tools

roundto [see code]

Rounds values to the nearest divisor value. See roundto_example.m for an example.

Return to list of tools

Simple visualization tool.

Return to list of tools

whichToolboxFor [see code]

Retrieves the required Matlab Toolboxes for specified mfile. Also inspects all files invoked by mfile and checks their dependency. Additionaly prints for every used toolbox the list of files that actually require them.

Return to list of tools

About

Miscellaneous Matlab Tools

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0