Showing posts with label Matlab. Show all posts
Showing posts with label Matlab. Show all posts

Thursday, January 3, 2019

Use your Java classes in Matlab

If you have Java classes which you want to use in your Matlab functions/scripts, you need to add the folders or the Java class themselves where they are saved into Matlab's Java class path.

Matlab's Java classpath is a list of folders which is automatically created at Matlab startup.
This list typically contains only folders of predefined Java classes which comes with Matlab itself.

To include additional Java classes, you need to:

  1. create a text file called javaclasspath.txt;
  2. insert on a line of that file the full path of the folder containing the Java class file or the full path of the Java class filename itself;
  3.  save such text file in Matlab's preferences folder.
Whether you need to include in the javaclasspath.txt file the full path of the folder containing a Java class file or the full path of the filename itself depends upon the type of Java class file. For example, for a Java class archive file (.jar file), you need to provide the full path of the filename itself. For more info, see the Matlab's online Help page about the Java class path or search Matlab's online Help for "Java class path".

To know what's your Matlab's preferences folder, type the command prefdir at Matlab's command line.


Friday, July 8, 2016

Import in Matlab temporal signals (waveforms) recorded in .hws files by a National Instruments digitizer

National Instruments digitizers can save temporal signals, i.e., waveforms, in binary files with a National Instruments' proprietary format called Hierarchical Waveform Storage, based upon the HDF5 format for data storage and representation.

A waveform stored in a file with that format contains not only the time series of the signal, rather a huge amount of other data and metadata about the measurement configuration and about the settings of the National Instruments digitizer.

These additional data and metadata can be extremely useful to recover information about scaling factors, sampling rate, instrument settings, etc. ...

A .hws is a HDF5 file, thus it can be explored and read in by Matlab using its built-in functions for reading HDF5 datasets and attributes.

See this post and this other one for a few hints about importing in Matlab a waveform stored in a .hws file.

Thursday, June 12, 2014

Extract data from a Matlab plot

Very useful instructions about how to extract the data plotted in a figure saved as a Matlab figure (.fig format file), in order to be able to re-plot the data in a different way.

http://www.mathworks.com/matlabcentral/answers/100687-how-do-i-extract-data-from-matlab-figures

Friday, April 12, 2013

Change the format for displaying numbers in Matlab's workspace

By default, Matlab shows in its workspace and at the command line numbers in a format that may not be suitable in all cases, e.g., when you have a large number of decimal digits.
The format of the number display can be changed by the built-in command

format Style

where Style indicates different formats.
See the Help page of the format built-in command for its syntax and the list of possible formats.

Import data into Matlab from an ASCII text file

A quick intro about the different built-in functions available in Matlab for importing data from an ASCII text file can be found at

http://www.mathworks.ch/ch/help/matlab/import_export/ways-to-import-text-files.html

The importdata function is particularly useful.

Sunday, June 24, 2012

Publication-ready EPS figures by Matlab

Matlab sucks when it comes to export figures in the EPS format: no bounding box, low quality, ...
Unless you use one of these two tools:

export_fig

EPS Utility Toolbox

Both of them are available on Matlab Central.

Friday, October 28, 2011

Matlab's graphical data tip precision

The graphical data tip in Matlab allows you to visualize the values of a point in a plot.
It comes with a certain decimal precision level already set as default (4 decimal digits).
You can change the default number of decimal digits.
See at the following Webpage,

http://www.cs.washington.edu/homes/dhalperi/useful.html

(thanks to Daniel Halperin for the suggestion).

2017 update

The previous instructions are valid for Matlab R2014a and older versions.
For Matlab R2014b and newer version, follow the suggestions from the following threads:

https://stackoverflow.com/questions/25477401/matlab-permanently-set-text-update-function-for-data-cursor-in-figures/39330765#39330765

Thanks to Michael Hirsch for pointing this out.

Monday, October 17, 2011

white spaces in strings built up by concatenating several substrings

In order to produce a string that contains white spaces, concatenating several different substring, use the [...] command and not Matlab's built-in function strcat(...).
The latter discards any white space contained in any substring.

Thursday, October 6, 2011

common properties for axes of different subplots/figures - linkaxes(...) Matlab built-in function

A useful bult-in function in Matlab is

linkaxes(...)


It allows to link together the axes of different subplots or even figures such that one can set the axes properties once for all the subplots/figures.

See the manpage at

http://www.mathworks.ch/help/techdoc/ref/linkaxes.html

Saturday, April 3, 2010

Current work directory in Matlab at startup time

I use Matlab on a daily basis for the post-processing and preliminary visualization of my simulation datasets.

Every time I upgrade Matlab to a newer version I face the following issue:

when Matlab starts, the current work directory is set to a default value, inside Matlab directory tree itself.

This default directory is of no use for me. Usually, I prefer to have as current work directory at startup time the one with which I've been working most recently.

To setup your preferred current work directory at startup time, you just need to run once the command


userpath('my preferred current work directory')

Next time you run Matlab, it will automatically setup your chosen directory as the current work one.

If you run Matlab via an shortcut icon on your desktop, under MS Windows, just be sure that the "Start in" field of the shortcut is empty (see image below) otherwise the directory you chose and setup via the
userpath(...) command will be overwritten by the one inserted in the shortcut's "Start in" field.