# MATLAB SDK

<figure><img src="https://3590686807-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwEBNWlmdcxXBXd7oyqyR%2Fuploads%2Fr1j0JEp6JZOGVeqhJVy2%2Fimage.png?alt=media&#x26;token=ef028654-880c-4d39-a5fe-321fc86e9c62" alt=""><figcaption><p>MATLAB allows for complex custom analysis on data that is stored in Marple DB</p></figcaption></figure>

## Installation

1. The SDK is currently shipped as a `DB.m` file, get the latest file in the [Marple SDK](https://gitlab.com/marpledata/marple-sdk/-/blob/main/matlab/DB.m?ref_type=heads) Gitlab repository.
2. Place `DB.m` in your current directory, or in a directory that is on your MATLAB `path` so that it's reachable by your scripts.
3. Create a file `config.json` in the same directory as the `DB.m` script. Add the following values:

```json
{
    // might be a different URL if you have self-hosted or VPC Marple
    "api_url": "https://db.marpledata.com/api/v1",
    "api_key": "<your-api-token-here>",
    "workspace": "<name of your workspace>"
}
```

## Usage

```matlab
% create a DB object
mdb = DB.from_config();

% list data streams
mdb.get_streams()

% list files for a data stream, also contains metadata
mdb.get_datasets('flight data')

% get time series data
mdb.get_data('2025-11-04-cessna-looping-test.tdms', 'altitude')
```

`mdb.get_data` will always return a [MATLAB table](https://nl.mathworks.com/help/matlab/ref/table.html?overload=table+false\&websocket=on) with one column `time` and one column with the name of the signal requested. The time is always given in nanoseconds, and as a UTC timestamp if the original data was datetimes.

<div align="left"><figure><img src="https://3590686807-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwEBNWlmdcxXBXd7oyqyR%2Fuploads%2Fzd0gaTMzQcdpERcJb8pO%2Fimage.png?alt=media&#x26;token=ac13b906-da2b-414f-8325-7313989ddc22" alt=""><figcaption></figcaption></figure></div>

If you want to combine multiple tables, it might require resampling of your signals to be able to combine them into calculations or visualisations. You can use built-in MATLAB functions to do this:

```matlab
data = mdb.get_data('2025-11-04-cessna-looping-test.tdms', 'altitude')

% resample signal
t1 = datetime(data.time/1e9, 'ConvertFrom','posixtime', 'TimeZone','UTC');
TT = table2timetable(table(data, data.altitude, 'VariableNames', {'time', 'altitude'}), 'RowTimes','time');
TT_altitude = retime(TT, 'regular', 'nearest', 'TimeStep', seconds(2));

% combine into one big table
TT_all_data = synchronize(TT_altitude, TT_speed, TT_battery, 'union', 'nearest');

```

## Caching

The MATLAB SDK builds up automatic caching of data that you have used in previous runs of your script. On each run, the SDK will check if it needs the fetch the data from Marple DB or not. This speeds up your scripts a lot if you are doing similar analysis multiple times, or if you are continuously tweaking a script.

The cache files are located at `cold/` in your current working directory.

## Discover the MATLAB SDK in 1 minute

{% embed url="<https://youtu.be/trH-LmBoTLY>" %}

Want to discover more Marple features in 1 minute? Check out other [1-minute-marple-videos](https://docs.marpledata.com/docs/other-resources/1-minute-marple-videos "mention")
