Selection Matlab version from Groovy script

I have two MATALB versions (R2023b and R2022b) installed in my Jenkins Agent.
I’m using Groovy script and configured Pipeline to run with Build configuration from Groovy file, by using “Jenkins Remote File Provider Plugin”.

Installed MATALB plugin and I want to execute runMATLABCommand() method, but Jenkins is taking MATLAB R2023 version as default.
I want to know, how I can input MATLAB version R2022b in Groovy.

Identified that R2023b path is added above R2022b in Jenkins Agent->System Information->java.library.path

I tried swapping the R2023b and R2022b path locations in “Environment variables” page of Agent PC and restarted Jenkins Agent service, but it is not reflected in java.library.path

In Groovy script, I have defined Jenkins Agent node name, similarly, is there any possibility to define MATLAB version name.

Groovy Script for Node name:
class Context {

String node = 'Windows'


Tried "String matlab = ‘R2022b’ "below node definition in groovy script, but it didn’t worked.

Was that done for the correct user?
You might want to try the following

withEnv(['PATH+MATHLAB=<path-to-matlab-R2022b>']) {

Thanks you @mawinter69

It worked.

withEnv(['PATH+MATLAB=C:\\Program Files\\MATLAB\\R2022b\\bin']){

Regarding user, I did those changes in System Variables of Administrator account.