<div class="section-label"><span class="num">04</span> MATLAB</div>
<div class="section-title">The MATLAB package for this <em>API</em>.</div>
Add the client to your path, set your credentials, call Grid, and read the forecast. This is an HTTP client, not a MathWorks toolbox.
> [!note]
> Desktop MATLAB often does not inherit shell environment variables. Pass <span class="mono">apiKey=</span> and <span class="mono">accessId=</span> to the constructor, or <span class="mono">setenv</span> in <span class="mono">startup.m</span>.
## Install
MATLAB does not install this from a package manager. Download the repository once, then add the `matlab` folder (the one that contains `+rbpengineapi`) to your path.
From the MATLAB command window, no Git required:
```matlab
root = fullfile(userpath, "rbp-engine-api-client-main");
if ~isfolder(fullfile(root, "matlab", "+rbpengineapi"))
zipFile = fullfile(tempdir, "rbp-engine-api-client.zip");
websave(zipFile, ...
"https://github.com/CambridgeSportsAnalytics/rbp-engine-api-client/archive/refs/heads/main.zip");
unzip(zipFile, userpath);
end
addpath(fullfile(root, "matlab"));
savepath
```
If you already cloned [rbp-engine-api-client](https://github.com/CambridgeSportsAnalytics/rbp-engine-api-client):
```matlab
addpath("/path/to/rbp-engine-api-client/matlab")
savepath
```
Then:
```matlab
client = rbpengineapi.Client(); % or Client(apiKey="...", accessId="...")
```
## Grid
```matlab
client = rbpengineapi.Client();
envelope = client.predictGrid( ...
[0.1, 0.2, 0.3], ...
[1, 0; 0, 1; 1, 1]);
yhat = envelope.results.yhat;
```
`predictGrid` submits the job and waits. The forecast is `envelope.results.yhat`. Fit and Grid insights sit on the same `results` object. What those numbers mean: [[Functions/Grid Prediction|Grid Prediction]] · [[Results/Grid Insights|Grid Insights]].
Example: [post_grid.m](https://github.com/CambridgeSportsAnalytics/rbp-engine-api-client/blob/main/matlab/examples/post_grid.m).
## MaxFit and PSR
```matlab
envelope = client.predictMaxfit(y, X);
envelope = client.predictPsr(y, X);
```
`predictPsr` is named so it does not mask MATLAB `predict`. Use MaxFit when the attribute set is fixed. Use PSR when the thresholds are fixed too. Examples: [post_maxfit.m](https://github.com/CambridgeSportsAnalytics/rbp-engine-api-client/blob/main/matlab/examples/post_maxfit.m) · [post_predict.m](https://github.com/CambridgeSportsAnalytics/rbp-engine-api-client/blob/main/matlab/examples/post_predict.m).
## Options
Omit `options` to use defaults. Pass a struct only for keys you want to change. Names match [[Settings/Options|Settings]]. For logistic outcomes, set `prediction_scale="logistic"`.
## Several circumstances
Pass several rows of `theta`. The client waits for every row.
```matlab
envelope = client.predictGrid(y, X, theta=[0, 1; 1, 0]);
```
Example: [post_predict_experiment.m](https://github.com/CambridgeSportsAnalytics/rbp-engine-api-client/blob/main/matlab/examples/post_predict_experiment.m).
## Submit without waiting
`postGrid`, `postMaxfit`, and `postPredict` return a receipt immediately. Call `waitResults(receipt)` when you want the forecast.
## Large X, one field, quota
Keep compact JSON `X` under **5 MiB**; this package does not upload yet. Upload from [[API/Clients/Python|Python]] and pass `struct("s3_key", "...")`, or shrink the matrix. [[API/Limits/Payload Limits|Payload size]]
`getResultsField` and `getQuota` match the Python client. [[API/Limits/Throttle Limits|Quota]]
## If something goes wrong
Failures are `rbpengineapi.ApiError` with `statusCode` and `body`. 401 is a bad key, 413 is `X` too large, 429 is quota, 409 is a job that failed while running.
Calling HTTP yourself: [post_predict_http.m](https://github.com/CambridgeSportsAnalytics/rbp-engine-api-client/blob/main/matlab/examples/post_predict_http.m) · [[API/Endpoints/Grid|Endpoints]].
## Related
- [[API/Clients/Introduction|Clients]] · [[API/Clients/Python|Python]] · [[API/Clients/R|R]]
- [[API/Introduction|API]] · [[Functions/Grid Prediction|Grid Prediction]]
<div class="btn-row center">
<a class="btn-primary" href="/API/Clients/Python">Python</a>
<a class="btn-ghost" href="/API/Clients/R">R</a>
</div>