MATLAB

MATLAB constructs like parfor arrow-up-rightcan be leveraged in applications using local parallel poolsarrow-up-right. Nuvolos will configure MATLAB to use the appropriate number of CPUs automatically, so you can start your parpool simply with the command:

pp = parpool('local');

The pool will be deleted after 30 minutes of idle time or with an application restart. To delete it manually, use

pp.delete()

Issue with starting the parallel pool

You might have encountered lately the following error message in MATLAB on Nuvolos when starting a new parallel pool:

Mismatch between number of environment names and values

This is due to a recent change by MathWorks regarding the online login process. The workaround is to issue the following command in the MATLAB terminal:

parallel.internal.mwa.ensureLoggedIn()

This will open up a dialog where you need to enter again your MathWorks credentials. After that, MATLAB will be able to start the parallel pool.

circle-info

You might not see a blinking cursor in the textbox for your credentials in the popup, but you can still type there.

Using OpenAI LLMs with MATLAB

The llms-with-matlabarrow-up-right repository provides a comprehensive interface for connecting MATLAB to large language models like OpenAI's GPT-5. This enables you to leverage AI capabilities for code generation, data analysis, and scientific research tasks directly within your MATLAB workflow.

Installation

circle-info

The MATLAB R2025b app version in Nuvolos (updated 2026-01-08) already has the llms-with-matlab add-on pre-installed on startup. You can start using it immediately without manual installation.

If you're using an older MATLAB version or need to install manually, clone the llms-with-matlab repository and add it to your MATLAB path:

Alternatively, you can download the repository as a ZIP file and extract it to your workspace.

Configuration with OpenAI API

To use the llms-with-matlab tools with OpenAI's GPT-5 model, you need to configure your API key.

circle-exclamation

We recommend storing your OpenAI API key as a Nuvolos secret, which will be automatically exposed as an environment variable in your MATLAB application. See Environment Variables and Secrets for details on how to set up secrets.

Set up your OPENAI_API_KEY as a Nuvolos secret. Once configured, the secret will be available as an environment variable when your MATLAB application starts.

You can verify the environment variable is available in MATLAB:

Basic Chat Completion Example

Here's a simple example to get started with chat completions using GPT-5:

This will produce responses like:

Example: Analyzing Scientific Papers and Generating Replication Code

This example demonstrates how to use the llms-with-matlab repository to analyze a scientific paper and generate MATLAB code for replicating the methodology. The example is based on the AnalyzeScientificPapersUsingFunctionCallsarrow-up-right workflow.

Step 1: Set Up OpenAI Chat with Function Calling

Create an openAIChat object configured to interact with GPT-5 and define a custom function for extracting paper details:

Step 2: Analyze a Scientific Paper

Provide the paper content or URL to the model and request analysis:

Step 3: Handle Function Calls and Execute Code

Process the model's response and extract the generated MATLAB code:

Example Output

The model might generate MATLAB code like this:

Additional Use Cases

The llms-with-matlab repository supports many other applications:

  • Code optimization: Ask the model to improve existing MATLAB code

  • Documentation generation: Generate comments and help text for functions

  • Algorithm selection: Get recommendations for appropriate algorithms based on your data

  • Debugging assistance: Describe errors and get suggestions for fixes

For more examples and documentation, visit the llms-with-matlab repositoryarrow-up-right.

MATLAB Copilot

MATLAB Copilot is an AI assistant optimized specifically for the MATLAB desktop environment. It provides generative AI-powered capabilities to help with MATLAB workflows, code development, and learning.

circle-info

MATLAB Copilot is available as part of campus-wide MATLAB licenses and does not require a GitHub account, OpenAI account, or API key. It is a separate service from GitHub Copilot and the OpenAI API integration described above.

Key Features

MATLAB Copilot offers several capabilities to enhance your MATLAB productivity:

  • Chat with MATLAB Copilot: Ask questions and get responses based on MathWorks documentation and code examples

  • Generate or Modify Code: Describe the code you want, and MATLAB Copilot will create new code or edit existing code

  • Code Explanations: Get easy-to-follow explanations of unfamiliar code or add comments to your code

  • Error Explanations: Receive explanations and troubleshooting recommendations for error messages

  • Autocomplete Code: Save time with automatically generated code predictions as you type

  • Create Tests: Generate test cases to verify code correctness (requires MATLAB Test)

Getting Started

MATLAB Copilot is available in recent versions of MATLAB and requires a valid license. To start using MATLAB Copilot:

  1. Open Copilot Chat: In the MATLAB desktop, access the Copilot Chat panel from the toolbar or use the keyboard shortcut

  2. Ask Questions: Type your questions or requests in natural language

  3. Review Suggestions: MATLAB Copilot will provide code snippets, explanations, or solutions based on your request

  4. Insert Code: Accept suggestions to insert generated code directly into your scripts

Example Usage

Here are some common ways to use MATLAB Copilot:

Best Practices

  • Be specific: Provide clear and detailed descriptions of what you want to achieve

  • Iterate: Refine your requests based on the initial responses

  • Verify: Always review and test generated code before using it in production

  • Learn: Use explanations to understand MATLAB concepts and improve your skills

For more information about MATLAB Copilot, including tutorials and detailed documentation, visit the MATLAB Copilot product pagearrow-up-right or access the Introduction to MATLAB Copilot coursearrow-up-right.

Last updated

Was this helpful?