Difference between revisions of "How Do I Configure the Matlab Interface?"

From BESA® Wiki
Redirect page
Jump to: navigation, search
(Redirected page to MATLAB Interface#Configuration)
 
(19 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
#REDIRECT [[MATLAB_Interface#Configuration]]
 +
 
{{BESAInfobox
 
{{BESAInfobox
 
|title = Module information
 
|title = Module information
 
|module = BESA Research Basic or higher
 
|module = BESA Research Basic or higher
|version = 5.2 or higher
+
|version = BESA Research 5.2 or higher
 
}}
 
}}
  
 
== MATLAB must be installed ==
 
== MATLAB must be installed ==
  
For step 2 (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\"'').
+
For the next step (required for MATLAB versions 2009b and over):
[[File:SystemProperties.png|thumb|500px|Figure 1 Advanced system settings]]
+
* We need to know whether the '''32-bit''' or '''64-bit''' version of MATLAB is installed.
[[File:EnvironmentVariables.png|thumb|500px|Figure 2 Environment variables]]
+
* We also need to know the path to the MATLAB installation (e.g. '''C:\Program Files\MATLAB\2009b\''').
[[File:EditSystemVariable.png|thumb|500px|Figure 3 Edit system variable]]
+
[[File:SendToMatlab.png|thumb|500px|Figure 3 Send marked segment to Matlab]]
+
[[File:SendToMatlabProgressbar.png|thumb|500px|Figure 4 Send to Matlab progress bar]]
+
[[File:ExportedMatlabStructure.png|thumb|500px|Figure 5 Data exported from BESA Research to Matlab]]
+
  
  
 +
== Setting PATH environment variable ==
  
== 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 (Windows logo key + Pause).
 +
** In Windows XP, the dialog is opened directly.
 +
** In Windows Vista and Windows 7, the key combination opens the ''"System Display"''. Click on the link ''"Change Settings"''.
 +
** In Windows 8 and Windows 10, 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.
 +
 
 +
* Select the "'''Advanced'''" tab in the ''"System Properties"'' dialog.
 +
* Press the "'''Environment Variables...'''" button.
 +
* Under "'''System variables'''" click on the "'''Path'''" variable, and then click the ''"Edit..."'' button.
 +
** In the resulting dialog, enter a semicolon (;) at the end of the path string, and add the path after the semicolon.
 +
** In Windows 10, click the ''"New"'' button in the resulting dialog and then add the path
 +
* Click ''"OK"'' to close and save the path variable. Click ''"OK"'' to close the ''"System Properties"'' dialog. When using Windows Vista/7/8/10, you will also need to close the ''"Control Panel"'' window afterwards.
 +
 
 +
<div><ul>
 +
<li style="display: inline-block;"> [[File:SystemProperties.png|thumb|340px|Figure 1. Advanced system settings]] </li>
 +
<li style="display: inline-block;"> [[File:EnvironmentVariables.png|thumb|300px|Figure 2. Environment variables]] </li>
 +
<li style="display: inline-block;"> [[File:EditSystemVariable.png|thumb|250px|Figure 3. Edit system variable]] </li>
 +
</ul></div>
  
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 the 64-bit version for Matlab 2009b is typically ''"C:\Program Files\MATLAB\R2009b\bin\win64"''. For the 32-bit version, the path is typically ''"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.
 
* Select the ''"Advanced"'' tab.
 
* 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.
 
  
 
== Additional configuration ==
 
== Additional configuration ==
  
(only required after a change of your MATLAB configuration after installation of BESA Research)
+
=== ConfigureBesaMatlabInterface.exe ===
  
During the installation process of BESA Research, the program "SetupBesaMatlabInterface.exe" in the BESA Research root folder was executed. Run this program again when your MATLAB configuration has changed, e.g. after updating your MATLAB version.
+
[[File:ConfigureBesaMatlabInterface_01.png|250px]]
 +
 
 +
(Only required after a change of your MATLAB configuration after installation of BESA Research)
 +
 
 +
During the installation process of BESA Research, the program <span style="color:#ff9c00;">ConfigureBesaMatlabInterface.exe</span> (or SetupBesaMatlabInterface.exe) in the BESA Research root folder (e.g.: '''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 "<span style="color:#ff9c00;">BesaMatlab.dll</span>" (32-bit version) or "<span style="color:#ff9c00;">BesaMatlab64.dll</span>" (64-bit version), and
 +
* If you are using a 64-bit version, it creates an entry in [[The Initialization File: BESA.ini|BESA.ini]] (e.g.: '''C:\Users\Public\Documents\BESA\Research_7_0''') as follows:
  
In the dropdown list, select the Matlab version that you are using. This program performs two operations:
 
* it copies the appropriate interface Dll 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 as follows:
 
 
<source lang="dos">
 
<source lang="dos">
 
[Matlab]  
 
[Matlab]  
Line 44: Line 63:
 
</source>
 
</source>
  
 +
=== BesaMatlab64Interface.exe ===
 +
 +
[[File:BesaMatlab64Interfaces_01.png|200px]]
 +
 +
'''Note: This step is not needed from BESA Research 7.1 March 2021.'''
 +
 +
If the installed MATLAB is 64-bit version, please run the program <span style="color:#ff9c00;">BesaMatlab64Interface.exe</span> in the BESA Research root folder (e.g.: '''C:\Program Files (x86)\BESA\Research_7_0'''). If the MATLAB path is set properly, a program window as the screenshot below is shown up without an error message. After that please just close the window.
 +
 +
[[File:BesaMatlab64Interfaces_02.png|400px]]
 +
 +
== 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:
 +
 +
# Make sure that in the "'''Path'''" environment variable only the path to one MATLAB version exists.
 +
# Make sure that the correct MATLAB interface dll (<span style="color:#ff9c00;">BesaMatlab.dll</span> (32-bit version) or <span style="color:#ff9c00;">BesaMatlab64.dll</span> (64-bit version)) is installed by starting the tool <span style="color:#ff9c00;">ConfigureBesaMatlabInterface.exe</span> (or SetupBesaMatlabInterface.exe) and selecting the corresponding MATLAB version and architecture.
 +
# Run '''CMD (Command Prompt) as administrator''', and then execute the following command <source lang="dos">matlab -regserver</source> ([https://www.mathworks.com/help/matlab/matlab_external/register-matlab-as-automation-server.html registers MATLAB as a Component Object Model (COM) server]).
 +
#* Close the CMD window (there should be no error message).
 +
#* 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.
 +
# Run '''CMD (Command Prompt) as NOT administrator''', and then execute the following command <source lang="dos">matlab -automation</source> ([https://www.mathworks.com/help/matlab/matlab_external/creating-the-server-manually.html Manually create automation server]: start MATLAB as a Component Object Model (COM) Automation server. MATLAB does not display the splash screen).
 +
#* Close the CMD and MATLAB Command Window (there should be no error message).
  
 
== Testing ==
 
== 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.)
+
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 interface: open a data file, mark a short (e.g. 1 s) time range, and select File / Send to Matlab to open the Export Dialog:
+
 
* The Matlab window should open, and BESA Research will display a progress bar:
+
Test the MATLAB interface
* After the window closes, open the Matlab window, and type "Workspace" to open the workspace window, or "Desktop" to open the standard Matlab desktop.
+
* 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).
* Examine the "besa_channels" variable, which contains the data for the marked data segment.
+
* 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 '''<code>workspace</code>''' to open the workspace window (Fig. 6), or '''<code>desktop</code>''' to open the standard MATLAB desktop.
 +
* Examine the <code>besa_channels</code> variable, which contains the data for the marked data segment.
 +
 
 +
<div><ul>
 +
<li style="display: inline-block;"> [[File:SendToMatlab.png|thumb|400px|Figure 4. Send marked segment to MATLAB]] </li>
 +
<li style="display: inline-block;"> [[File:SendToMatlabProgressbar.png|thumb|200px|Figure 5. Send to MATLAB progress bar]] </li>
 +
<li style="display: inline-block;"> [[File:ExportedMatlabStructure.png|thumb|300px|Figure 6. Data exported from BESA Research to MATLAB]] </li>
 +
</ul></div>
  
  
 
== Troubleshooting if the interface is not working after the above steps ==
 
== 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 (step 2 above) is not defined properly, or that the interface Dll BesaMatlab.dll or BesaMatlab64.dll is not compatible with the currently installed version of Matlab.
+
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.
 +
 
  
 
[[Category:Setup]]
 
[[Category:Setup]]

Latest revision as of 15:40, 6 May 2021