# How Do I Configure the Matlab Interface?

 Module information Modules BESA Research Basic or higher Version 5.2 or higher

## MATLAB must be installed

For the next step (required for MATLAB versions 2009b and over):

• We need to know whether the 32-bit or 64-bit version of MATLAB is installed.
• We also need to know the path to the MATLAB installation (e.g. C:\Program Files\MATLAB\2009b\).

## Setting PATH environment variable

For versions 2009b and over, make sure that the path to the Win32 or Win64 folder in the MATLAB installation to the PATH environment variable is defined:

• The path for MATLAB 2009b:
• The path for the 64-bit version: C:\Program Files\MATLAB\R2009b\bin\win64
• The path for the 32-bit version: C:\Program Files\MATLAB\R2009b\bin\win32
• Open the "System Properties" dialog by holding down the "Windows" key and pressing the "Pause" key at the same time.
• In XP, the dialog is opened directly.
• In Vista and Window 7, the key combination opens the "System Display". Click on the link "Change Settings".
• In Windows 8, the key combination also opens the "System Display". Click on the link "Advanced system settings". Skip the step in this description, as you have already chosen the advanced settings.
• Press the "Environment Variables" button.
• Under "System variables" click on the "Path" variable and then click "Edit". In the resulting dialog, enter a semicolon (;) at the end of the path string, and add the path after the semicolon.
• Click "OK" to close and save the path variable. Click "OK" to close the "System Properties" dialog. When using Windows Vista/7/8, you will also need to close the "Control Panel" window afterwards.
• Figure 1. Advanced system settings
• Figure 2. Environment variables
• Figure 3. Edit system variable

### ConfigureBesaMatlabInterface.exe

(Only required after a change of your MATLAB configuration after installation of BESA Research)

During the installation process of BESA Research, the program ConfigureBesaMatlabInterface.exe (or SetupBesaMatlabInterface.exe) in the BESA Research root folder (C:\Program Files (x86)\BESA\Research_7_0) was executed.

Run this program as administrator again when your MATLAB configuration has changed, e.g. after updating your MATLAB version. In the dropdown list, select the MATLAB version that you are using.

This program performs two operations:

• It copies the appropriate interface dll file to the BESA Research root folder and renames it to "BesaMatlab.dll" (32-bit version) or "BesaMatlab64.dll" (64-bit version), and
• If you are using a 64-bit version it creates an entry in BESA.ini (C:\Users\Public\Documents\BESA\Research_7_0) as follows:
[Matlab]
Platform=64

### BesaMatlab64Interface.exe

If the installed MATLAB is 64-bit version, please run the program BesaMatlab64Interface.exe in the BESA Research root folder (C:\Program Files (x86)\BESA\Research_7_0). If the MATLAB path is set properly, one program window is shown up without an error message. After that please just close the window.

## Updating the MATLAB Interface after MATLAB Upgrade

Sometimes, the BESA to MATLAB interface stops working after installation of new/additional MATLAB version on one computer. The reason is the registry change/corruption caused by the newly installed version. In order to correct this, one has to perform the following steps:

1. Make sure that in the "Path" environment variable only the path to one MATLAB version exists.
2. Make sure that the correct Matlab.dll is installed by starting the tool ConfigureBesaMatlabInterface.exe and selecting the corresponding Matlab version and architecture.
3. Run CMD (Command Prompt) as administrator, and then execute the following command
matlab -regserver
(registers MATLAB as a Component Object Model (COM) server).
4. Sometimes if the MATLAB license is connected to a specific user account and the user account does not have administrator rights it could be problematic to execute that command. In that case change the corresponding account to an administrator account and then perform the actions again. After that the account could be made to regular user account again.

## Testing

Start BESA Research and check if Send to MATLAB... is displayed in the File menu. If it is, the interface is set up correctly. Note that the item will be grayed if no file is open in BESA Research.

Test the MATLAB interface

• Open a data file, mark a short (e.g. 1 s) time range, and select File / Send to MATLAB... to open the Export data dialog (Fig. 4).
• The MATLAB window should open, and BESA Research will display a progress bar (Fig. 5).
• After the window closes, open the MATLAB window, and type workspace to open the workspace window (Fig. 6), or desktop to open the standard MATLAB desktop.
• Examine the besa_channels variable, which contains the data for the marked data segment.
• Figure 4. Send marked segment to MATLAB
• Figure 5. Send to MATLAB progress bar
• Figure 6. Data exported from BESA Research to MATLAB

## Troubleshooting if the interface is not working after the above steps

If the File / Send to MATLAB... menu item is not shown, this means that either the path (the above step for Setting PATH environment variable) is not defined properly, or that the interface Dll (BesaMatlab.dll or BesaMatlab64.dll) is not compatible with the currently installed version of MATLAB.