# MATLAB SDK

<figure><img src="/files/bvGCIiB0aaHdFFEzQLEH" 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="/files/RLAP2xrEcYqFXaTDzy1y" 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](/docs/other-resources/1-minute-marple-videos.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.marpledata.com/docs/sdk/overview/matlab-sdk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
