Matlab
function arguments validation
syntax is generally recommended over validateattributes() and inputParser().
Function arguments validation specification coerces the input and/or output variables to the class declaration given if possible, and errors otherwise.
Default values are easily specified, which required such verbose syntax before.
only a single class can be specified
recall the .empty method of most Matlab classes e.g. datetime.empty() that allows initializing an empty array.
Matlab argument validation syntax coerces class at runtime.
Currently GNU Octave does not enable function arguments validation syntax, but it is possible to use the function albeit with warnings like:
“function arguments validation blocks are not supported; INCORRECT RESULTS ARE POSSIBLE”
To elide the verbose warnings to allow for self-tests or quick use, do in Octave like:
warning('off', 'all')% whatever code you want to run that uses the Matlab arguments validation syntaxoruntests .% restore warningswarning('on', 'all')
There are
requests
for Octave to assign a warning ID so that only this warning can be silenced, but it is not implemented as of this writing.
Thus all warnings are silenced, which is not recommended in production code.
However, for self-tests or quick use, it could be acceptable.
Intel oneAPI is a useful, performant compiler for CI with the C, C++, and Fortran languages.
oneAPI compilers give useful debugging output at build and run time.
If having trouble determining the oneAPI APT package name, examine the APT repo Packages file on the developer computer like:
curl -O https://apt.repos.intel.com/oneapi/dists/all/main/binary-amd64/Packages.gz
gunzip Packages.gz
less Packages
Matlab .mltbx toolbox packaged toolbox format is proprietary to Matlab.
Oftentimes we desire to
distribute a Matlab package as a set of .m source files
instead.
To add a “toolbox” or “package” to Matlab and use functions from that toolbox requires using “addpath” or “import” Matlab syntax.
This example makes those paths persistent in Matlab and Octave, using example toolbox directories ~/mypkg1 and ~/mypkg2.
Normally use addpath() instead of cd().
Do not put brackets or braces around the multiple paths.
Prepend a package to the Matlab path by editing the startup.m file from Matlab or Octave:
edit(fullfile(userpath,'startup.m'))
put in addpath() commands to the desired Matlab packages paths like:
addpath('~/mypkg1','~/mypkg2')
Restart Matlab/Octave and type
path
and the new toolbox directories will be at the top.
Matlab requires compilers for mex -setup langage used (C / C++ / Fortran) and Matlab Engine for the respective code language.
Windows Matlab supported
compiler
locations are communicated to Matlab via environment variables.
It’s possible to switch between compilers that are setup with MEX.
Choosing compilers is generally not possible on Linux or macOS from within Matlab.
If a oneAPI version compatible with Matlab is installed on Windows, Matlab may detect it and allow switching compilers.
If a different compiler is detected and allowed by Matlab, commands to choose the compiler will be at the bottom of the output when using the “mex -setup” commands below.
If having trouble with mex -setup for example if setup fails on macOS like:
“sh: /var/folders/…/mex_…: No such file or directory”
Try running the mex -setup command from Terminal using Matlab batch mode to see if Matlab’s shell was breaking setup.
This usually fixes the setup issue.
In our cases, we found that environment variables MATLAB_SHELL and SHELL (see matlab7rc.sh on
Linux
or
macOS
)
were already set appropriately (not the generic /bin/sh), but we still had to run the mex -setup command from Terminal.
matlab -batch "mex -setup C -v"matlab -batch "mex -setup C++ -v"matlab -batch "mex -setup Fortran -v"
Once MEX is working, consider using Matlab
buildtool
build system for simple, terse syntax to build and test MEX and Matlab Engine code.
Using MinGW on Windows with Matlab requires having an exact version of MinGW supported by Matlab.
For example, the version of MinGW with MSYS2 is generally not supported by Matlab.
Tell Matlab the supported MinGW compiler path via Windows environment variable
MW_MINGW64_LOC.
Matlab might not use newly-compiled MEX functions if the function cache is not cleared.
This can happen when the MEX function was previously called before building the MEX code.
Detect if the MEX implementation of a function is being used in memory:
functiony =is_mex_fun(name)y = endsWith(which(name), mexext());
end
Example: Matlab function timestwo.m and optionally MEX compiled function also called timestwo.
functiony =timestwo(x)disp("this is plain Matlab script")
y = 2 * x;
end
If one builds the MEX function with the same name and then calls the function, Matlab may not use the MEX compiled version until the function cache is cleared.
Clear
the Matlab function cache, thereby enabling newly-compiled MEX functions to be used by command
clear functions
% orclear all
% thenassert(is_mex_fun("timestwo"))
Eavesdropping / injection vulnerabilities allow unencrypted wireless mouse connection to be used as a keyboard by attackers to
inject
unwanted
keystrokes,
possibly taking over your PC.
Force pairing allows unauthorized input to the PC.
Logitech device firmware has distinct per-OS update procedures.
On Windows, the Logitech Unifying software:
winget install Logitech.UnifyingSoftware
is used to update firmware and pair receivers with mice and keyboards.
In Logitech Unifying software click Advanced → Update Firmware
On Linux,
fwupdsupports
updating Logitech Unifying receivers.
Modern Linux distros will raise a prompt to seamlessly update Logitech receiver firmware.
On Linux, check firmware version and pair devices to the Logitech Unifying receiver with
Solaar.
Fwupd: list all recognized devices, including firmware versions where applicable:
For C or C++ projects with incorrect #define logic or due to compiler bugs, it may be necessary to avoid CMake internally set definitions like -DNDEBUG.
CMake internally sets -DNDEBUG when the CMAKE_BUILD_TYPE is set to Release, RelWithDebInfo, or MinSizeRel.
In general, Matplotlib figures look better with
constrained_layout.
The older
tight_layout
is not as flexible and can lead to overlapping text, particularly with “suptitle”.
To make figures with subplots and suptitle work better, use:
importmatplotlib.pyplotaspltfg = plt.figure(layout='constrained')
ax = fg.subplots(3, 1)
for i inrange(3):
ax[i].plot(range(5+5*i))
fg.suptitle('lots of lines')
plt.show()
These are CMake MRs (Merge Requests) that have been or may be merged.
They are not yet in a CMake release, but they may be included in future releases.
ExternalProject set environment variables for each of the configure, build, test, and install steps. Previously this was a cumbersome syntax invoking cmake -E env or similar.
Fix Windows Console handling: CMake 4.1 aims to enable CMake Windows color console output and fix long-standing race conditions in Windows Console handling.
Xarray can write and load netCDF4 files into datasets.
Warning messages may appear when using older netCDF4 files with newer versions of Xarray or NumPy like:
RuntimeWarning: numpy.ndarray size changed, may indicate binary incompatibility. Expected 16 from C header, got 96 from PyObject
This may indicate underlying incompatibilities between the versions of Xarray, Pandas, NumPy, and the netCDF4 library.