Matlab

Matlab

MATLAB is a high-level language and interactive programming environment for numerical computation and visualization developed by MathWorks.
Royce  Reinger

Royce Reinger

1678710180

ARTE: ARTE (A Robotics Toolbox for Education)

ARTE is a Matlab toolbox focussed on robotic manipulators, both serial and parallel mechanisms are included.

The main features of ARTE are:

  • Simulate any industrial robot within a Matlab environment.
  • Represent a visualize the Denavit-Hartenberg's system on the robot.
  • 3D graphics of a great number of industrial robots are available.
  • You can plot and observe the position, velocity and acceleration of the joint coordinates of the robot when a movement is performed.
  • Also, the torques and forces at each joint can be plotted.
  • A GUI teaching pendant is available to move and program the robots.
  • The robots can be programmed and simulated ABB RAPID language. A step by step simulation of the programs can be carried out within the Matlab's editor and debugger.
  • A Matlab to RAPID interpreter is included that allows to program the real robot using your Matlab code.
  • New robot models can be easily included.
  • Practical exercises are provided.

Created by Arturo Gil: arturo.gil@umh.es. Miguel Hernández University, Spain.

ARTE is distributed under LGPL license.

INSTALL copy the directory containing all the .m files to a directory named arte3.3.X. To initialize the library, inside Matlab you should be placed in the directory where the library is installed:

#!matlab

>> pwd
ans =
/Users/arturo/Desktop/arte3.2.X

Next, in the Matlab command prompt type:

#!matlab

>> init_lib

To view all functions and demos type:

#!matlab

>>help Contents

If you want to have a fast view of the main capabilities of the library, type:

#!matlab

>> demos

YOUTUBE CHANNEL http://www.youtube.com/playlist?list=PLClKgnzRFYe72qDYmj5CRpR9ICNnQehup

ITUNES CHANNEL https://itunes.apple.com/es/itunes-u/robotica-umh1770-curso-2013/id681094508?mt=10

PRACTICAL EXERCISES WITH THE LIBRARY http://arvc.umh.es/arte/index_en.html#practicals

LIST OF ROBOTS SUPPORTED BY THE LIBRARY http://arvc.umh.es/arte/supported_robots.htmle/supported_robots.html}


Download Details:

Author: 4rtur1t0
Source Code: https://github.com/4rtur1t0/ARTE 

#machinelearning #matlab #robotics 

ARTE: ARTE (A Robotics Toolbox for Education)
Royce  Reinger

Royce Reinger

1676495520

HCTSA: Highly Comparative Time-series analysis

〰️ hctsa 〰️: highly comparative time-series analysis

hctsa is a Matlab software package for running highly comparative time-series analysis. It extracts thousands of time-series features from a collection of univariate time series and includes a range of tools for visualizing and analyzing the resulting time-series feature matrix, including:

  1. Normalizing and clustering time-series data;
  2. Producing low-dimensional representations of time-series data;
  3. Identifying and interpreting discriminating features between different classes of time series; and
  4. Fitting and evaluating multivariate classification models.

Installation 

For users familiar with git (recommended), please make a fork of the repo and then clone it to your local machine. To update, after setting an upstream remote (git remote add upstream git://github.com/benfulcher/hctsa.git) you can use git pull upstream main.

Users unfamiliar with git can instead download the repository by clicking the green "Code" button then "Download ZIP".

Once downloaded, you can install hctsa by running the install.m script (see docs for details).

Documentation and Wiki 📖

Comprehensive documentation for hctsa, from getting started through to more advanced analyses is on GitBook.

There is also alot of additional information on the wiki, including:

  • 👉 Information about alternative feature sets (including the much faster catch22), and information about other time-series packages available in R, python, and Julia.
  • 〰️ The accompanying time-series data archive for this project, CompEngine.
  • 💾 Downloadable hctsa feature matrices from time-series datasets with example workflows.
  • 💻 Resources for distributing an hctsa computation on a computing cluster.
  • 📕 A list of publications that have used hctsa to address different research questions.
  • 💁 Frequently asked questions about hctsa and related feature-based time-series analyses.

Acknowledgement 👍

If you use this software, please read and cite these open-access articles:

Feedback, as email, GitHub issues or pull requests, is much appreciated.

For commercial use of hctsa, including licensing and consulting, contact Engine Analytics.

External packages and dependencies

Many features in hctsa rely on external packages and Matlab toolboxes. In the case that some of them are unavailable, hctsa can still be used, but only a reduced set of time-series features will be computed.

hctsa uses the following Matlab Add-On Toolboxes: Statistics and Machine Learning, Signal Processing, Curve Fitting, System Identification, Wavelet, and Econometrics.

The following external time-series analysis code packages are provided with the software (in the Toolboxes directory), and are used by our main feature-extraction algorithms to compute meaningful structural features from time series:

Acknowledgements 👋

Many thanks go to Romesh Abeysuriya for helping with the mySQL database set-up and install scripts, and Santi Villalba for lots of helpful feedback and advice on the software.


Feel free to email me for advice on applications of hctsa 🤓


Download Details:

Author: Benfulcher
Source Code: https://github.com/benfulcher/hctsa 
License: View license

#machinelearning #python #matlab #analysis 

HCTSA: Highly Comparative Time-series analysis
Code  Camp

Code Camp

1669818274

MATLAB for Beginners - Crash Course

Learn the fundametnals of MATLAB in this tutorial for engineers, scientists, and students. MATLAB is a programming language and software suite used for data analysis, scientific computing, and visualization that is widely used in academia and industry.

⭐️ Contents ⭐️
⌨️(0:00:00) Intro
⌨️(0:00:19) MATLAB IDE
⌨️(0:01:33) Variables & Arithmetic
⌨️(0:14:19) Matrices, Arrays, & Linear Algebra
⌨️(0:24:54) The Index
⌨️(0:31:16) Example 1 - Equations
⌨️(0:45:09) Anonymous Functions
⌨️(0:47:57) Example 2 - Plotting
⌨️(1:05:29) Example 3 - Logic
⌨️(1:20:24) Example 4 - Random & Loops
⌨️(1:26:07) Sections
⌨️(1:28:20) For Loops
⌨️(1:40:09) Calculation Time
⌨️(1:42:57) Naming Conventions
⌨️(1:45:09) File Naming
⌨️(1:45:54) While Loop
⌨️(1:50:16) Custom Function
⌨️(1:56:47) Have a good one ;)

#matlab

MATLAB for Beginners - Crash Course

D4M.jl: A D4M Module for Julia

Julia-D4M

A Dynamic Distributed Dimensional Data Model(D4M) module for Julia. D4M was developed in MATLAB by Dr Jeremy Kepner and his team at Lincoln Labs. The goal is to implement D4M in a native Julia method. As a course project in Numeric Computation with Julia, various parts of this implementation has been completed and compared with the original matlab in performance. In the matrix performance example folder (testing performance in matrix like operations such as add and multiply), this implementation has achieved on par if not significant speed up (10x). This is thanks to the effectiveness of Julia base in comparision to Matlab.

The D4M Project Page: http://www.mit.edu/~kepner/D4M/

Current Status: (v0.5) - End of course project

  • Read and Write CSV
  • Printtable tabular
  • Basic and advanced Assoc method of indexing
  • All methods of construction Assoc implemented
  • Implemented 1Intro/1AssocIntro and 3Scaling/3MatrixPerformance example folders and dependency.

Next Version: (v0.6) [Mid Feburary]

  • Implement 1Intro/2EdgeArt and 2Apps/1EntityAnalysis example folders and dependency.
  • Add interfaces to Julia's native DataFrame, allowing user to transfer data back and forth from JuliaStats

Download Details:

Author: Achen12
Source Code: https://github.com/achen12/D4M.jl 
License: Apache-2.0 license

#julia #matlab #modules 

D4M.jl: A D4M Module for Julia

Moonwalk.jl: A Partial MATLAB to Julia Compiler

Moonwalk.jl

This is meant to be a partial MATLAB to Julia compiler, just to ease the transition of libraries.

Run with ./run_moonwalk.jl matlab_file.m.

Assumptions

  1. Valid Matlab
  2. No empty switch statements

Testing

Run ./MoonwalkTest.jl to run the test suite, or input specific numbers to run specific test cases (in the samples folder).

Download Details: 

Author: Diogo149
Source Code: https://github.com/diogo149/Moonwalk.jl 

#julia #matlab 

Moonwalk.jl: A Partial MATLAB to Julia Compiler

MATLAB.jl: Calling MATLAB in Julia Through MATLAB Engine

MATLAB

The MATLAB.jl package provides an interface for using MATLAB® from Julia using the MATLAB C api. In other words, this package allows users to call MATLAB functions within Julia, thus making it easy to interoperate with MATLAB from the Julia language.

You cannot use MATLAB.jl without having purchased and installed a copy of MATLAB® from MathWorks. This package is available free of charge and in no way replaces or alters any functionality of MathWorks's MATLAB product.

Overview

This package is composed of two aspects:

Creating and manipulating mxArrays (the data structure that MATLAB used to represent arrays and other kinds of data)

Communicating with MATLAB engine sessions

Warning:

MATLAB string arrays are not supported, and will throw an error exception. This also applies if they are nested within a MATLAB struct. This is a limitation of the MATLAB C api. The MATLAB function convertContainedStringsToChars may be used to facilitate conversion to a compatible format for use with MATLAB.jl.

Threading is also not supported within Julia when using the MATLAB.jl library.

Installation

Important: The procedure to setup this package consists of the following steps.

By default, MATLAB.jl uses the MATLAB installation with the greatest version number. To specify that a specific MATLAB installation should be used, set the environment variable MATLAB_ROOT.

Windows

For Matlab R2020a onwards, you should be able to go directly to step 2. If you encounter issues, run matlab -batch "comserver('register')" in the command prompt. For earlier versions of Matlab, start a command prompt as an administrator and enter matlab /regserver.

From Julia run: Pkg.add("MATLAB")

Linux

Make sure matlab is in executable path.

Make sure csh is installed. (Note: MATLAB for Linux relies on csh to open an engine session.)

To install csh in Debian/Ubuntu/Linux Mint, you may type in the following command in terminal:

sudo apt-get install csh

From Julia run: Pkg.add("MATLAB")

Mac OS X

Ensure that MATLAB is installed in /Applications (for example, if you are using MATLAB R2012b, you may add the following command to .profile: export MATLAB_HOME=/Applications/MATLAB_R2012b.app).

From Julia run: Pkg.add("MATLAB")

Usage

MxArray class

An instance of MxArray encapsulates a MATLAB variable. This package provides a series of functions to manipulate such instances.

Create MATLAB variables in Julia

One can use the function mxarray to create MATLAB variables (of type MxArray), as follows

mxarray(Float64, n)   # creates an n-by-1 MATLAB zero array of double valued type
mxarray(Int32, m, n)  # creates an m-by-n MATLAB zero array of int32 valued type
mxarray(Bool, m, n)   # creates a MATLAB logical array of size m-by-n

mxarray(Float64, (n1, n2, n3))  # creates a MATLAB array of size n1-by-n2-by-n3

mxcellarray(m, n)        # creates a MATLAB cell array
mxstruct("a", "b", "c")  # creates a MATLAB struct with given fields

You may also convert a Julia variable to MATLAB variable

a = rand(m, n)

x = mxarray(a)     # converts a to a MATLAB array
x = mxarray(1.2)   # converts a scalar 1.2 to a MATLAB variable

a = sprand(m, n, 0.1)
x = mxarray(a)     # converts a sparse matrix to a MATLAB sparse matrix

x = mxarray("abc") # converts a string to a MATLAB char array

x = mxarray(["a", 1, 2.3])  # converts a Julia array to a MATLAB cell array

x = mxarray(Dict("a"=>1, "b"=>"string", "c"=>[1,2,3])) # converts a Julia dictionary to a MATLAB struct

The function mxarray can also convert a compound type to a Julia struct:

struct S
    x::Float64
    y::Vector{Int32}
    z::Bool
end

s = S(1.2, Int32[1, 2], false)

x = mxarray(s)   # creates a MATLAB struct with three fields: x, y, z
xc = mxarray([s, s])  # creates a MATLAB cell array, each cell is a struct.
xs = mxstructarray([s, s])  # creates a MATLAB array of structs

Note: For safety, the conversation between MATLAB and Julia variables uses deep copy.

When you finish using a MATLAB variable, you may call delete to free the memory. But this is optional, it will be deleted when reclaimed by the garbage collector.

delete(x)

Note: if you put a MATLAB variable x to MATLAB engine session, then the MATLAB engine will take over the management of its life cylce, and you don't have to delete it explicitly.

Access MATLAB variables

You may access attributes and data of a MATLAB variable through the functions provided by this package.

# suppose x is of type MxArray
nrows(x)    # returns number of rows in x
ncols(x)    # returns number of columns in x
nelems(x)   # returns number of elements in x
ndims(x)    # returns number of dimensions in x
size(x)     # returns the size of x as a tuple
size(x, d)  # returns the size of x along a specific dimension

eltype(x)   # returns element type of x (in Julia Type)
elsize(x)   # return number of bytes per element

data_ptr(x)   # returns pointer to data (in Ptr{T}), where T is eltype(x)

# suppose s is a MATLAB struct
mxnfields(s)    # returns the number of fields in struct s

You may also make tests on a MATLAB variable.

is_double(x)   # returns whether x is a double array
is_sparse(x)   # returns whether x is sparse
is_complex(x)  # returns whether x is complex
is_cell(x)     # returns whether x is a cell array
is_struct(x)   # returns whether x is a struct
is_empty(x)    # returns whether x is empty

...            # there are many more there

Convert MATLAB variables to Julia

a = jarray(x)   # converts x to a Julia array
a = jvector(x)  # converts x to a Julia vector (1D array) when x is a vector
a = jscalar(x)  # converts x to a Julia scalar
a = jmatrix(x)  # converts x to a Julia matrix
a = jstring(x)  # converts x to a Julia string
a = jdict(x)    # converts a MATLAB struct to a Julia dictionary (using fieldnames as keys)

a = jvalue(x)  # converts x to a Julia value in default manner

Read/Write MAT Files

This package provides functions to manipulate MATLAB's mat files:

mf = MatFile(filename, mode)    # opens a MAT file using a specific mode, and returns a handle
mf = MatFile(filename)          # opens a MAT file for reading, equivalent to MatFile(filename, "r")
close(mf)                       # closes a MAT file.

get_mvariable(mf, name)   # gets a variable and returns an mxArray
get_variable(mf, name)    # gets a variable, but converts it to a Julia value using `jvalue`

put_variable(mf, name, v)   # puts a variable v to the MAT file
                            # v can be either an MxArray instance or normal variable
                            # If v is not an MxArray, it will be converted using `mxarray`

put_variables(mf; name1=v1, name2=v2, ...)  # put multiple variables using keyword arguments

variable_names(mf)   # get a vector of all variable names in a MAT file

There are also convenient functions that can get/put all variables in one call:

read_matfile(filename)    # returns a dictionary that maps each variable name
                          # to an MxArray instance

write_matfile(filename; name1=v1, name2=v2, ...)  # writes all variables given in the
                                                  # keyword argument list to a MAT file

Both read_matfile and write_matfile will close the MAT file handle before returning.

Examples:

struct S
    x::Float64
    y::Bool
    z::Vector{Float64}
end

write_matfile("test.mat";
    a = Int32[1 2 3; 4 5 6],
    b = [1.2, 3.4, 5.6, 7.8],
    c = [[0.0, 1.0], [1.0, 2.0], [1.0, 2.0, 3.0]],
    d = Dict("name"=>"MATLAB", "score"=>100.0),
    s = "abcde",
    ss = [S(1.0, true, [1., 2.]), S(2.0, false, [3., 4.])] )

This example will create a MAT file called test.mat, which contains six MATLAB variables:

  • a: a 2-by-3 int32 array
  • b: a 4-by-1 double array
  • c: a 3-by-1 cell array, each cell contains a double vector
  • d: a struct with two fields: name and score
  • s: a string (i.e. char array)
  • ss: an array of structs with two elements, and three fields: x, y, and z.

Use MATLAB Engine

Basic Use

To evaluate expressions in MATLAB, one may open a MATLAB engine session and communicate with it. There are three ways to call MATLAB from Julia:

  • The mat"" custom string literal allows you to write MATLAB syntax inside Julia and use Julia variables directly from MATLAB via interpolation
  • The eval_string evaluate a string containing MATLAB expressions (typically used with the helper macros @mget and @mput
  • The mxcall function calls a given MATLAB function and returns the result

In general, the mat"" custom string literal is the preferred method to interact with the MATLAB engine.

Note: There can be multiple (reasonable) ways to convert a MATLAB variable to Julia array. For example, MATLAB represents a scalar using a 1-by-1 matrix. Here we have two choices in terms of converting such a matrix back to Julia: (1) convert to a scalar number, or (2) convert to a matrix of size 1-by-1.

The mat"" custom string literal

Text inside the mat"" custom string literal is in MATLAB syntax. Variables from Julia can be "interpolated" into MATLAB code by prefixing them with a dollar sign as you would interpolate them into an ordinary string.

using MATLAB

x = range(-10.0, stop=10.0, length=500)
mat"plot($x, sin($x))"  # evaluate a MATLAB function

y = range(2.0, stop=3.0, length=500)
mat"""
    $u = $x + $y
    $v = $x - $y
"""
@show u v               # u and v are accessible from Julia

As with ordinary string literals, you can also interpolate whole Julia expressions, e.g. mat"$(x[1]) = $(x[2]) + $(binomial(5, 2))".

eval_string

You may also use the eval_string function to evaluate MATLAB code as follows

eval_string("a = sum([1,2,3])")

The eval_string function also takes an optional argument that specifies which MATLAB session to evaluate the code in, e.g.

julia> s = MSession();
julia> eval_string(s, "a = sum([1,2,3])")
a =
     6

mxcall

You may also directly call a MATLAB function on Julia variables using mxcall:

x = -10.0:0.1:10.0
y = -10.0:0.1:10.0
xx, yy = mxcall(:meshgrid, 2, x, y)

Note: Since MATLAB functions behavior depends on the number of outputs, you have to specify the number of output arguments in mxcall as the second argument.

mxcall puts the input arguments to the MATLAB workspace (using mangled names), evaluates the function call in MATLAB, and retrieves the variable from the MATLAB session. This function is mainly provided for convenience. However, you should keep in mind that it may incur considerable overhead due to the communication between MATLAB and Julia domain.

@mget and @mput

The macro @mget can be used to extract the value of a MATLAB variable into Julia

julia> mat"a = 6"
julia> @mget a
6.0

The macro @mput can be used to translate a Julia variable into MATLAB

julia> x = [1,2,3]
julia> @mput x
julia> eval_string("y = sum(x)")
julia> @mget y
6.0
julia> @show y
a = 63.0

Calling custom MATLAB function

If the MATLAB function is not in the current directory, we need to first add it to the MATLAB path before calling through Julia:

mat"addpath('/path/to/folder')"
val = mat"myfunction($arg1, $arg2)"

For example, if there is a MATLAB file located at /path/to/folder with contents:

function [r,u] = test(x, y)
    r = x + y;
    u = x - y;
end

We can call this function as follows in Julia:

using MATLAB

x = range(-10.0, stop=10.0, length=500)
y = range(2.0, stop=3.0, length=500)

mat"addpath('/path/to/folder')"

r, u = mxcall(:test,2,x,y)

Viewing the MATLAB Session (Windows only)

To open an interactive window for the MATLAB session, use the command show_msession() and to hide the window, use hide_msession(). Warning: manually closing this window will result in an error or result in a segfault; it is advised that you only use the hide_msession() command to hide the interactive window.

Note that this feature only works on Windows.

# default
show_msession() # open the default MATLAB session interactive window
get_msession_visiblity() # get the session's visibility state
hide_msession() # hide the default MATLAB session interactive window

# similarily
s = MSession()
show_msession(s)
get_msession_visiblity(a)
hide_msession(s)

Advanced use of MATLAB Engines

This package provides a series of functions for users to control the communication with MATLAB sessions.

Here is an example:

s1 = MSession()    # creates a MATLAB session
s2 = MSession(0)   # creates a MATLAB session without recording output

x = rand(3, 4)
put_variable(s1, :x, x)  # put x to session s1

y = rand(2, 3)
put_variable(s2, :y, y)  # put y to session s2

eval_string(s1, "r = sin(x)")  # evaluate sin(x) in session s1
eval_string(s2, "r = sin(y)")  # evaluate sin(y) in session s2

r1_mx = get_mvariable(s1, :r)  # get r from s1
r2_mx = get_mvariable(s2, :r)  # get r from s2

r1 = jarray(r1_mx)
r2 = jarray(r2_mx)

# ... do other stuff on r1 and r2

close(s1)  # close session s1
close(s2)  # close session s2

Download Details: 

Author: JuliaInterop
Source Code: https://github.com/JuliaInterop/MATLAB.jl 
License: MIT license

#julia #matlab 

MATLAB.jl: Calling MATLAB in Julia Through MATLAB Engine

MatlabCompat.jl: Source of MatlabCompat.jl

MatlabCompat.jl

Julia library aimed at simplifying conversion of legacy MATLAB/Octave code into Julia by providing functions similar to MATLAB/Octave

Julia is a new language with a dynamically growing community. It has a lot of syntax similarities to MATLAB/Octave with potential to build higher performance software. Because of this many developers in technical computing consider switching from MATLAB/Octave to Julia. This switch however maybe quite difficult in situations when one has a bulk amount of legacy code running on the daily basis. To simplify to transition of your legacy MATLAB/Octave code we have developed "MatlabCompat" a Julia library with a collection of functions rewritten from scratch under an open source MIT "Expat" license and some are named similarly to functions in MATLAB/Octave.

However, as a word of caution Julia is not MATLAB/Octave and was never meant to be. This library is not meant to substitute any commercial products (including those of Mathworks Inc.), nor is it meant to make Julia language closer to MATLAB/Octave. THe one and sole purpose of this library is to pave a way for enthusiast MATLB/Octave developers willing to engage with Julia open source language. For more information and help please refer to the Julia language homepage

Developer

Symlink the latest version of the package at hand.

git clone https://github.com/MatlabCompat/MatlabCompat.jl && cd MatlabCompat.jl
julia -e 'Pkg.init(); run(`ln -s $(pwd()) $(Pkg.dir("MatlabCompat"))`); Pkg.pin("MatlabCompat"); Pkg.resolve()'

On Windows you might want to use:

mklink

If you have any troubles simply remove the folder in your home folder and try again.

Afterwards check that Pkg.status() contains this package (with a master (dirty) side note)

Dependencies

We use following Julia packages:

julia 0.4 Tk Images ImageView FixedPointNumbers MAT Color BinDeps ImageMagick

Also see REQUIRE file for details.

Package Help can be found here

Contribution guide can be found here

Download Details: 

Author: MatlabCompa
Source Code: https://github.com/MatlabCompat/MatlabCompat.jl 
License: View license

#julia #matlab 

MatlabCompat.jl: Source of MatlabCompat.jl

MAT.jl: Julia Module for Reading MATLAB Files

MAT.jl

Read and write MATLAB files in Julia

This library can read MATLAB .mat files, both in the older v5/v6/v7 format, as well as the newer v7.3 format.

Installation

This is installed using the standard tools of the package manager:

pkg> add MAT

where you get the pkg> prompt by hitting ] as the first character of the line. (Exit pkg mode by hitting backspace or Ctrl-C as the first character of the line.)

See also the requirements for the HDF5 module, used for "v7.3" files and for writing *.mat files.

Usage

To load the module:

using MAT

To read a single variable from a MAT file (compressed files are detected and handled automatically):

file = matopen("matfile.mat")
read(file, "varname") # note that this does NOT introduce a variable ``varname`` into scope
close(file)

To write a variable to a MAT file:

file = matopen("matfile.mat", "w")
write(file, "varname", variable)
close(file)

To read all variables from a MAT file as a Dict:

vars = matread("matfile.mat")

To write a Dict to a MAT file, using its keys as variable names. The compress argument is optional, and compression is off by default:

matwrite("matfile.mat", Dict(
    "myvar1" => 0,
    "myvar2" => 1
); compress = true)

To get a list of variable names in a MAT file:

file = matopen("matfile.mat")
varnames = keys(file)
close(file)

To check for the presence of a variable name in a MAT file:

file = matopen("matfile.mat")
if haskey(file, "variable")
    # something
end
close(file)

Caveats

  • All files are written in MATLAB v7.3 format.
  • MATLAB v4 files are not currently supported.

Credits

The MAT_HDF5 module, which provides read/write support for MATLAB v7.3 files, was written primarily by Tim Holy. The MAT_v5 module, which provides read support for MATLAB v5/v6/v7 files, was written primarily by Simon Kornblith.

Download Details: 

Author: JuliaIO
Source Code: https://github.com/JuliaIO/MAT.jl 
License: MIT license

#julia #matlab 

MAT.jl: Julia Module for Reading MATLAB Files

Mexjulia: Embedding Julia in The MATLAB Process

mexjulia: embedding Julia in the MATLAB process.

Note: this project is effectively in hibernation as its author no longer has access to matlab.

Prerequisites

mexjulia requires MATLAB (tested with R2016b) and Julia (>=v.0.6-dev) along with a C++ compiler configured to work with MATLAB's mex command, the last is required for building the mexjulia MEX function. You can check that a compiler is properly configured by executing:

>> mex -setup C++

from the MATLAB command prompt.

Configuration

Start MATLAB and navigate to the mexjulia directory. Once there, run:

>> jl.config

You will be prompted to select a julia executable. The build process will:

  1. use julia to determine build options,
  2. build the mexjulia MEX function from source,
  3. add the mexjulia directory to your MATLAB path.

Call jl.config any time you want to build against a different version of Julia. You can pass in the path to the desired Julia executable to build against if you don't want to be prompted to select one.

Quick start

Use jl.eval to parse and evaluate MATLAB strings as Julia expressions:

>> jl.eval('2+2')

ans =

  int64

   4

You can evaluate multiple expressions in a single call:

>> [s, c] = jl.eval('sin(pi/3)', 'cos(pi/3)')

s =

    0.8660


c =

    0.5000

Julia's STDOUT and STDERR are redirected to the MATLAB console:

>> jl.eval('println("Hello, world!")');
Hello, world!
>> jl.eval('warn("Oh, no!")');
WARNING: Oh, no!

One can avoid the parentheses and string quotes using jleval (a simple wrapper around jl.eval) and MATLAB's command syntax:

>> jleval 1 + 1

ans =

  int64

   2

>> jleval println("Hello, world!")
Hello, world!

Use jl.call to call a Julia function specified by its name as a string:

>> jl.call('factorial', 10)

ans =

     3628800

jl.call marshals MATLAB data to/from Julia making certain default choices for doing so.

Load new Julia code by calling jl.include:

>> jl.include('my_own_julia_code.jl')

Exercise more control over how data is marshaled between MATLAB and Julia by defining a Julia function with a "MEX-like" signature and invoking it with jl.mex:

>> jleval double_it(args::Vector{MxArray}) = [2*jvalue(arg) for arg in args]
>> a = rand(5,5)

a =

    0.6443    0.9390    0.2077    0.1948    0.3111
    0.3786    0.8759    0.3012    0.2259    0.9234
    0.8116    0.5502    0.4709    0.1707    0.4302
    0.5328    0.6225    0.2305    0.2277    0.1848
    0.3507    0.5870    0.8443    0.4357    0.9049

>> jl.mex(1, 'double_it', a)

ans =

    1.2886    1.8780    0.4155    0.3895    0.6222
    0.7572    1.7519    0.6025    0.4518    1.8468
    1.6232    1.1003    0.9418    0.3414    0.8604
    1.0657    1.2450    0.4610    0.4553    0.3696
    0.7015    1.1741    1.6886    0.8714    1.8098

The first argument to jl.mex is the number of return values to expect. The second is the name of the function to be invoked. All remaining arguments are treated as function arguments. jl.mex expects the functions on which it is invoked to accept a single argument of type Vector{MxArray} and to return an iterable collection of values on which mxarray may be successfully invoked (e.g., a value of type Vector{MxArray}).

See lmdif_test.m, lm.m, and lmdif.jl for a more complex example that exposes Optim.jl's Levenberg-Marquardt solver to MATLAB. It presents an example of a MATLAB function handle being passed to Julia and used as a callback. (The default marshaling wraps matlab function handles in an anonymous function.)

Known Issues

  • On Windows, if a julia is on the path it must be the one against which mexjulia is built.

Download Details: 

Author: juliamatlab
Source Code: https://github.com/juliamatlab/mexjulia 
License: MIT license

#julia #matlab 

Mexjulia: Embedding Julia in The MATLAB Process

Mex.jl: Embedding Julia in the MATLAB Process

In this tutorial, we'll learn about Mex.jl, embedding Julia in the MATLAB process using MATLAB's C++ Mex interface. This allows Julia functions to be called from MATLAB. This also allows (embedded) Julia to call MATLAB functions.

Mex.jl

Embedding Julia in the MATLAB process

Mex.jl embeds Julia into the MATLAB process using MATLAB's C++ Mex interface. This allows Julia functions to be called from MATLAB. This also allows (embedded) Julia to call MATLAB functions.

Prerequisites

Mex.jl requires MATLAB and Julia along with a C++ compiler configured to work with MATLAB's mex command, the last is required for building the mexjulia MEX function. You can check that a compiler is properly configured by executing:

>> mex -setup C++

from the MATLAB command prompt.

NOTE: This project currently only supports Julia 1.5. Support for Julia 1.6 and greater will be possible when the changes resulting from https://github.com/JuliaLang/julia/issues/42411 are incorporated into the latest stable release of Julia.

Installation

First ensure that the MATLAB.jl Julia package can be properly installed.

Then enter the package manager by typing ] and then run the following:

pkg> add Mex

The build process will:

  1. use julia to determine build options,
  2. build the mexjulia MEX function from source,
  3. add the mexjulia directory to your MATLAB path.

By default, Mex.jl uses the MATLAB installation with the greatest version number. To specify that a specific MATLAB installation should be used, set the environment variable MATLAB_ROOT.

Quick start

Use jl.eval to parse and evaluate MATLAB strings as Julia expressions:

>> jl.eval('2+2')

ans =

  int64

   4

You can evaluate multiple expressions in a single call:

>> [s, c] = jl.eval('sin(pi/3), cos(pi/3)')

s =

    0.8660


c =

    0.5000

Note that Julia's STDOUT and STDERR are not redirected to the MATLAB console. But if MATLAB is launched from the terminal they will appear there.

>> jl.eval('println("Hello, world!")');
>> jl.eval('@warn("Oh, no!")');

One can avoid the parentheses and string quotes using jleval (a simple wrapper around jl.eval) and MATLAB's command syntax:

>> jleval 1 + 1

ans =

  int64

   2

>> jleval println("Hello, world!")
Hello, world!

Use jl.call to call a Julia function specified by its name as a string:

>> jl.call('factorial', int64(10))

ans =

     3628800

Load new Julia code by calling jl.include:

>> jl.include('my_own_julia_code.jl')

Exercise more control over how data is marshaled between MATLAB and Julia by defining a Julia function with a "MEX-like" signature and invoking it with jl.mex:

>> jleval import MATLAB
>> jleval double_it(args::Vector{MATLAB.MxArray}) = [2*MATLAB.jvalue(arg) for arg in args]
>> a = rand(5,5)

a =

    0.6443    0.9390    0.2077    0.1948    0.3111
    0.3786    0.8759    0.3012    0.2259    0.9234
    0.8116    0.5502    0.4709    0.1707    0.4302
    0.5328    0.6225    0.2305    0.2277    0.1848
    0.3507    0.5870    0.8443    0.4357    0.9049

>> jl.mex('double_it', a)

ans =

    1.2886    1.8780    0.4155    0.3895    0.6222
    0.7572    1.7519    0.6025    0.4518    1.8468
    1.6232    1.1003    0.9418    0.3414    0.8604
    1.0657    1.2450    0.4610    0.4553    0.3696
    0.7015    1.1741    1.6886    0.8714    1.8098

The first argument to jl.mex is the name of the function to be invoked. All remaining arguments are treated as function arguments.

jl.mex expects the functions on which it is invoked to accept a single argument of type Vector{MATLAB.MxArray} and to return an iterable collection of values on which MATLAB.mxarray may be successfully invoked (e.g., a value of type Vector{MATLAB.MxArray}).

Additional Examples

Additional usage examples may be found in the examples folder.

Performance

To learn how to reduce the overhead associated with this package, see performance.m in the example folder.

Download Details: 
Author: byuflowlab
Source Code: https://github.com/byuflowlab/Mex.jl 
License: MIT
#julia #matlab

Mex.jl: Embedding Julia in the MATLAB Process

MATDaemon.jl: Calling Julia from MATLAB

In this tutorial, we'll learn about MATDaemon.jl, calling Julia from MATLAB. Calling MATLAB code from Julia via the C API has been supported for many years via MATLAB.jl

MATDaemon.jl

Call Julia from MATLAB using a Julia daemon launched by DaemonMode.jl.

Quickstart

Use the MATLAB function jlcall.m to call Julia from MATLAB:

>> jlcall('sort', {rand(2,5)}, struct('dims', int64(2)))

ans =

    0.1270    0.2785    0.6324    0.8147    0.9575
    0.0975    0.5469    0.9058    0.9134    0.9649

The positional arguments passed to jlcall.m are:

  1. The Julia function to call, given as a MATLAB char array. This can be any Julia expression which evaluates to a function. For example, 'a=2; b=3; x -> a*x+b'. For convenience, the empty string '' is interpreted as '(args...; kwargs...) -> nothing', returning nothing for any inputs. Note: expressions are wrapped in a let block and evaluated in the global scope
  2. Positional arguments, given as a MATLAB cell array. For example, args = {arg1, arg2, ...}
  3. Keyword arguments, given as a MATLAB struct. For example, kwargs = struct('key1', value1, 'key2', value2, ...)

The first time jlcall.m is invoked:

  1. MATDaemon.jl will be installed into a local Julia project, if one does not already exist. By default, a folder .jlcall is created in the same folder as jlcall.m
  2. A Julia server will be started in the background using DaemonMode.jl

All subsequent calls to Julia are run on the Julia server. The server will be automatically killed when MATLAB exits.

Restarting the Julia server

In the event that the Julia server reaches an undesired state, the server can be restarted by passing the 'restart' flag with value true:

>> jlcall('', 'restart', true) % restarts the Julia server and returns nothing

Similarly, one can shutdown the Julia server without restarting it:

>> jlcall('', 'shutdown', true) % shuts down the Julia server and returns nothing

Setting up the Julia environment

Before calling Julia functions, it may be necessary or convenient to first set up the Julia environment. For example, one may wish to activate a local project environment, run setup scripts, import modules for later use, or set the number of threads for running multithreaded code.

This setup can be conveniently executed at the start of your MATLAB script with a single call to jlcall.m as follows:

>> jlcall('', ...
    'project', '/path/to/MyProject', ... % activate a local Julia Project
    'setup', '/path/to/setup.jl', ... % run a setup script to load some custom Julia code
    'modules', {'MyProject', 'LinearAlgebra', 'Statistics'}, ... % load a custom module and some modules from Base Julia
    'threads', 'auto', ... % use the default number of Julia threads
    'restart', true ... % start a fresh Julia server environment
    )

See the corresponding sections below for more details about these flags.

Julia multithreading

The number of threads used by the Julia server can be set using the 'threads' flag:

>> jlcall('() -> Threads.nthreads()', 'threads', 8, 'restart', true)

ans =

  int64

   8

The default value for 'threads' is 'auto', deferring to Julia to choose the number of threads.

Note: Julia cannot change the number of threads at runtime. In order for the 'threads' flag to take effect, the server must be restarted.

Loading modules

Julia modules can be loaded and used:

>> jlcall('LinearAlgebra.norm', {[3.0; 4.0]}, 'modules', {'LinearAlgebra'})

ans =

     5

Note: modules are loaded using import, not using. Module symbols must therefore be fully qualified, e.g. LinearAlgebra.norm in the above example as opposed to norm.

Persistent environments

By default, previously loaded Julia code is available on subsequent calls to jlcall.m. For example, following the above call to LinearAlgebra.norm, the LinearAlgebra.det function can be called without loading LinearAlgebra again:

>> jlcall('LinearAlgebra.det', {[1.0 2.0; 3.0 4.0]})

ans =

    -2

Unique environments

Set the 'shared' flag to false in order to evaluate each Julia call in a separate namespace on the Julia server:

% Restart the server, setting 'shared' to false
>> jlcall('LinearAlgebra.norm', {[3.0; 4.0]}, 'modules', {'LinearAlgebra'}, 'restart', true, 'shared', false)

ans =

     5

% This call now errors, despite the above command loading the LinearAlgebra module, as LinearAlgebra.norm is evaluated in a new namespace
>> jlcall('LinearAlgebra.norm', {[3.0; 4.0]}, 'shared', false)
ERROR: LoadError: UndefVarError: LinearAlgebra not defined
Stacktrace:
 ...

Unique Julia instances

Instead of running Julia code on a persistent Julia server, unique Julia instances can be launched for each call to jlcall.m by passing the 'server' flag with value false.

Note: this may cause significant overhead when repeatedly calling jlcall.m due to Julia package precompilation and loading:

>> tic; jlcall('x -> sum(abs2, x)', {1:5}, 'server', false); toc
Elapsed time is 4.181178 seconds. % call unique Julia instance

>> tic; jlcall('x -> sum(abs2, x)', {1:5}, 'restart', true); toc
Elapsed time is 5.046929 seconds. % re-initialize Julia server

>> tic; jlcall('x -> sum(abs2, x)', {1:5}); toc
Elapsed time is 0.267088 seconds. % call server; significantly faster

Loading code from a local project

Code from a local Julia project can be loaded and called:

>> jlcall('MyProject.my_function', args, kwargs, ...
    'project', '/path/to/MyProject', ...
    'modules', {'MyProject'})

Note: the string passed via the 'project' flag is simply forwarded to Pkg.activate; it is the user's responsibility to ensure that the project's dependencies have been installed.

Loading setup code

Julia functions may require or return types which cannot be directly passed from or loaded into MATLAB. For example, suppose one would like to query Base.VERSION. Naively calling jlcall('() -> Base.VERSION') would fail, as typeof(Base.VERSION) is not a String but a VersionNumber.

One possible remedy is to define a wrapper function in a Julia script:

# setup.jl
julia_version() = string(Base.VERSION)

Then, use the 'setup' flag to pass the above script to jlcall.m:

>> jlcall('julia_version', 'setup', '/path/to/setup.jl')

ans =

    '1.6.1'

In this case, jlcall('() -> string(Base.VERSION)') would work just as well. In general, however, interfacing with complex Julia libraries using MATLAB types may be nontrivial, and the 'setup' flag allows for the execution of arbitrary setup code.

Note: the setup script is loaded into the global scope using include; when using persistent environments, symbols defined in the setup script will be available on subsequent calls to jlcall.m.

Handling Julia outputs

Output(s) from Julia are returned using the MATLAB cell array varargout, MATLAB's variable-length list of output arguments. A helper function MATDaemon.matlabify is used to convert Julia values into MATLAB-compatible values. Specifically, the following rules are used to populate varargout with the Julia output y:

  1. If y::Nothing, then varargout = {} and no outputs are returned to MATLAB
  2. If y::Tuple, then length(y) outputs are returned, with varargout{i} given by matlabify(y[i])
  3. Otherwise, one output is returned with varargout{1} given by matlabify(y)

The following matlabify methods are defined by default:

matlabify(x) = x # default fallback
matlabify(::Union{Nothing, Missing}) = zeros(0,0) # equivalent to MATLAB's []
matlabify(x::Symbol) = string(x)
matlabify(xs::Tuple) = Any[matlabify(x) for x in xs] # matlabify values
matlabify(xs::Union{<:AbstractDict, <:NamedTuple, <:Base.Iterators.Pairs}) = Dict{String, Any}(string(k) => matlabify(v) for (k, v) in pairs(xs)) # convert keys to strings and matlabify values

Note: MATLAB cell and struct types correspond to Array{Any} and Dict{String, Any} in Julia.

Conversion via matlabify can easily be extended to additional types. Returning to the example from the above section, we can define a matlabify method for Base.VersionNumber:

# setup.jl
MATDaemon.matlabify(v::Base.VersionNumber) = string(v)

Now, the return type will be automatically converted:

>> jlcall('() -> Base.VERSION', 'setup', '/path/to/setup.jl')

ans =

    '1.6.1'

Performance

MATLAB inputs and Julia ouputs are passed back and forth between MATLAB and the DaemonMode.jl server by writing to temporary .mat files. The location of these files can be configured with the 'infile' and 'outfile' flags, respectively. Pointing these files to a ram-backed file system is recommended when possible (for example, the /tmp folder on Linux is usually ram-backed), as read/write speed will likely improve. This is now the default; 'infile' and 'outfile' are created via the MATLAB tempname function (thanks to @mauro3 for this tip).

Nevertheless, this naturally leads to some overhead when calling Julia, particularly when the MATLAB inputs and/or Julia outputs have large memory footprints. It is therefore not recommended to use jlcall.m in performance critical loops.

MATLAB and Julia version compatibility

This package has been tested on a variety of MATLAB versions. However, for some versions of Julia and MATLAB, supported versions of external libraries may clash. For example, running jlcall.m using Julia v1.6.1 and MATLAB R2015b gives the following error:

>> jlcall

ERROR: Unable to load dependent library ~/.local/julia-1.6.1/bin/../lib/julia/libjulia-internal.so.1

Message: /usr/local/MATLAB/R2015b/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by ~/.local/julia-1.6.1/bin/../lib/julia/libjulia-internal.so.1)

This error results due to a clash of supported libstdc++ versions, and does not occur when using e.g. Julia v1.5.4 with MATLAB R2015b, or Julia v1.6.1 with MATLAB R2020b.

If you encounter this issue, see the Julia and MATLAB documentation for information on mutually supported external libraries.

About this package

This repository contains utilities for parsing and running Julia code, passing MATLAB arguments to Julia, and retrieving Julia outputs from MATLAB.

The workhorse behind MATDaemon.jl and jlcall.m is DaemonMode.jl which is used to start a persistent Julia server in the background.

Download Details: 
Author: jondeuce
Source Code: https://github.com/jondeuce/MATDaemon.jl 
License: MIT
#julia #matlab

MATDaemon.jl: Calling Julia from MATLAB
Vaughn  Sauer

Vaughn Sauer

1658622780

MatLab/Octave Examples Of Popular Machine Learning Algorithms

Machine Learning in MatLab/Octave

For Python/Jupyter version of this repository please check homemade-machine-learning project.

This repository contains MatLab/Octave examples of popular machine learning algorithms with code examples and mathematics behind them being explained.

The purpose of this repository was not to implement machine learning algorithms using 3rd party libraries or Octave/MatLab "one-liners" but rather to practice and to better understand the mathematics behind each algorithm. In most cases the explanations are based on this great machine learning course.

Supervised Learning

In supervised learning we have a set of training data as an input and a set of labels or "correct answers" for each training set as an output. Then we're training our model (machine learning algorithm parameters) to map the input to the output correctly (to do correct prediction). The ultimate purpose is to find such model parameters that will successfully continue correct input→output mapping (predictions) even for new input examples.

Regression

In regression problems we do real value predictions. Basically we try to draw a line/plane/n-dimensional plane along the training examples.

Usage examples: stock price forecast, sales analysis, dependency of any number, etc.

🤖 Linear Regression - example: house prices prediction.

Classification

In classification problems we split input examples by certain characteristic.

Usage examples: spam-filters, language detection, finding similar documents, handwritten letters recognition, etc.

🤖 Logistic Regression - examples: microchip fitness detection, handwritten digits recognitions using one-vs-all approach.

Unsupervised Learning

Unsupervised learning is a branch of machine learning that learns from test data that has not been labeled, classified or categorized. Instead of responding to feedback, unsupervised learning identifies commonalities in the data and reacts based on the presence or absence of such commonalities in each new piece of data.

Clustering

In clustering problems we split the training examples by unknown characteristics. The algorithm itself decides what characteristic to use for splitting.

Usage examples: market segmentation, social networks analysis, organize computing clusters, astronomical data analysis, image compression, etc.

🤖 K-means algorithm - example: split data into three clusters.

Anomaly Detection

Anomaly detection (also outlier detection) is the identification of rare items, events or observations which raise suspicions by differing significantly from the majority of the data.

Usage examples: intrusion detection, fraud detection, system health monitoring, removing anomalous data from the dataset etc.

🤖 Anomaly Detection using Gaussian distribution - example: detect overloaded server.

Neural Network (NN)

The neural network itself isn't an algorithm, but rather a framework for many different machine learning algorithms to work together and process complex data inputs.

Usage examples: as a substitute of all other algorithms in general, image recognition, voice recognition, image processing (applying specific style), language translation, etc.

🤖 Neural Network: Multilayer Perceptron (MLP) - example: handwritten digits recognition.

Machine Learning Map

Machine Learning Map

The source of the following machine learning topics map is this wonderful blog post

How to Use This Repository

Install Octave or MatLab

This repository contains *.m scripts that are intended to be run in Octave or MatLab. Thus in order to launch demos you need either Octave or MatLab to be installed on you local machine. In case of MatLab you may also use its web-version.

Run Demos

In order to run the demo of your choice you should move to the chosen folder (i.e. neural-network):

cd neural-network

Launch Octave console:

octave

Launch demo script from Octave console:

demo

To see all demo variables you may launch:

whos

To exit the demo you may launch:

exit

Also be aware that demo scripts opens additional window with charts and other graphical information that is related to the running algorithm. You may find screenshots of the window that each demo will render for you on the dedicated README files for each machine learning algorithm.

Demos


Author: trekhleb
Source code: https://github.com/trekhleb/machine-learning-octave
License: MIT license

#machine-learning #matlab #algorithm 

MatLab/Octave Examples Of Popular Machine Learning Algorithms
Vaughn  Sauer

Vaughn Sauer

1658615460

PRMLT: Matlab Code Of Machine Learning Algorithms in Book PRML

Introduction

This Matlab package implements machine learning algorithms described in the great textbook: Pattern Recognition and Machine Learning by C. Bishop (PRML).

It is written purely in Matlab language. It is self-contained. There is no external dependency.

Note: this package requires Matlab R2016b or latter, since it utilizes a new Matlab syntax called Implicit expansion (a.k.a. broadcasting). It also requires Statistics Toolbox (for some simple random number generator) and Image Processing Toolbox (for reading image data).

Design Goal

  • Succinct: The code is extremely compact. Minimizing code length is a major goal. As a result, the core of the algorithms can be easily spotted.
  • Efficient: Many tricks for speeding up Matlab code are applied (e.g. vectorization, matrix factorization, etc.). Usually, functions in this package are orders faster than Matlab builtin ones (e.g. kmeans).
  • Robust: Many tricks for numerical stability are applied, such as computing probability in logrithm domain, square root matrix update to enforce matrix symmetry\PD, etc.
  • Readable: The code is heavily commented. Corresponding formulas in PRML are annoted. Symbols are in sync with the book.
  • Practical: The package is not only readable, but also meant to be easily used and modified to facilitate ML research. Many functions in this package are already widely used (see Matlab file exchange).

Installation

Download the package to a local folder (e.g. ~/PRMLT/) by running:

git clone https://github.com/PRML/PRMLT.git

Run Matlab and navigate to the folder (~/PRMLT/), then run the init.m script.

Run some demos in ~/PRMLT/demo folder. Enjoy!

FeedBack

If you find any bug or have any suggestion, please do file issues. I am graceful for any feedback and will do my best to improve this package.

License

Released under MIT license

Contact

sth4nth at gmail dot com


Author: PRML
Source code: https://github.com/PRML/PRMLT
License: MIT license

#matlab #machine-learning 

PRMLT: Matlab Code Of Machine Learning Algorithms in Book PRML
Vaughn  Sauer

Vaughn Sauer

1658608080

PRT: Pattern Recognition and Machine Learning in MATLAB

PRT: Pattern Recognition and Machine Learning in MATLAB

A free and permissively licensed object oriented approach to machine learning in MATLAB.

Machine learning and pattern recognition are everywhere. MATLAB is a high level interpreted language widely used throughout academia and engineering due to its ease of use and numerous available toolboxes. Currently available toolboxes for pattern recognition and machine learning in MATLAB are either costly or restrictively licensed. The PRT is a MIT licensed toolbox that provides access to a wide range of pattern recognition techniques in an easy to use unified framework. The PRT provides a suite of MATLAB commands and data-types to help you organize, visualize, process, cluster and classify your data. If you have data and need to make predictions based on your data, the PRT can help.


Author: covartech
Source code: https://github.com/covartech/PRT
License: MIT license


#matlab #machine-learning 

PRT: Pattern Recognition and Machine Learning in MATLAB
Dylan  Iqbal

Dylan Iqbal

1650421904

How to Use Colormaps in MATLAB

How to Use Colormaps in MATLAB

Learn how to utilize colormaps in MATLAB® to more effectively visualize and convey 2D and 3D graphics objects. This video will dive into what colormaps consist of, how to create and customize colormaps, and how to compute with colormaps.

- View example code: https://bit.ly/3sumCNu 

#matlab

How to Use Colormaps in MATLAB