visual3d:documentation:third-party:matlab:matlab
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
visual3d:documentation:third-party:matlab:matlab [2025/09/03 13:45] – wikisysop | visual3d:documentation:third-party:matlab:matlab [2025/09/18 15:22] (current) – [Examples] wikisysop | ||
---|---|---|---|
Line 8: | Line 8: | ||
- Visual3D will [[# | - Visual3D will [[# | ||
- Release 12 and 13 of Matlab can be [[# | - Release 12 and 13 of Matlab can be [[# | ||
- | |||
- | |||
- | |||
- | ====Matlab Page Contents==== | ||
- | - [[# Matlab Dll's| Matlab Dll' | ||
- | - [[# Transferring Information between Visual3D and MATLAB| Transferring Information between Visual3D and MATLAB]] | ||
- | - [[# FIR and IRR Filter Design and Analysis| FIR and IRR Filter Design and Analysis]] | ||
- | - [[# Visual3D Pipeline Commands| Visual3D Pipeline Commands]] | ||
===== Matlab Dll's ===== | ===== Matlab Dll's ===== | ||
Line 45: | Line 37: | ||
Communication between Visual 3D and compiled Matlab functions takes place by way of MAT files. MAT files are data files, readable only by Matlab and Visual 3D, that can contain any number of signal, event, or parameter data. | Communication between Visual 3D and compiled Matlab functions takes place by way of MAT files. MAT files are data files, readable only by Matlab and Visual 3D, that can contain any number of signal, event, or parameter data. | ||
- | Data can be exported from Visual 3D to a MAT file by using the EXPORT_MATFILE command. This command allows you to save signal data and parameter data from Visual 3D into MAT format so it can be read by a Matlab function. You must specify the file name of the file from which the data is to be taken, the signal name, the signal type, whether or not the signal is processed or not, and the output name. The output name is simply the name of the variable that is saved in the MAT file; this is not necessarily the same as the signal name (see below). In addition to this, if you want to export parameters (data from the PARAMETERS branch of the data tree), you can include the PARAMETER_GROUPS, | + | Data can be exported from Visual 3D to a MAT file by using the EXPORT_MATFILE command. This command allows you to save signal data and parameter data from Visual 3D into MAT format so it can be read by a Matlab function. You must specify the file name of the file from which the data is to be taken, the signal name, the signal type, whether or not the signal is processed or not, and the output name. The output name is simply the name of the variable that is saved in the MAT file; this is not necessarily the same as the signal name (see below). In addition to this, if you want to export parameters (data from the PARAMETERS branch of the data tree), you can include the PARAMETER_GROUPS, |
- | + | ||
- | Sample Matlab Function: [[https:// | + | |
- | < | + | |
- | ! CALL_MFILE | + | |
- | ! - save specified signals to a mat file | + | |
- | ! - run an exe compiled from Matlab that | + | |
- | ! reads a mat file | + | |
- | ! creates a new mat file | + | |
- | ! - load the new mat file into Visual3D | + | |
- | ! | + | |
- | !/ | + | |
- | ! specify the entire directory path | + | |
- | !/ | + | |
- | ! from Visual3D | + | |
- | !/ | + | |
- | !/ | + | |
- | !/ | + | |
- | ! | + | |
- | !/ | + | |
- | ! file. These are the names that | + | |
- | ! the .m file will see | + | |
- | ! | + | |
- | !/ | + | |
- | !/ | + | |
- | ! | + | |
- | !/ | + | |
- | ! when they are imported to Visual3D | + | |
- | !/ | + | |
- | ! | + | |
- | </ | + | |
- | + | ||
- | This example uses the ExampleTrial data that can be downloaded from the website.\\ | + | |
- | + | ||
- | < | + | |
- | CALL_MFILE | + | |
- | / | + | |
- | / | + | |
- | / | + | |
- | / | + | |
- | / | + | |
- | / | + | |
- | / | + | |
- | / | + | |
- | / | + | |
- | / | + | |
- | </ | + | |
- | + | ||
- | The CALL_MFILE command performs the following tasks:\\ | + | |
- | *Exports data to a MAT file. | + | |
- | * Runs a compiled Matlab-based .exe file to load the data, process the data, and create a new MAT file containing the processed data. | + | |
- | * Imports the data from the second MAT file back into Visual 3D. | + | |
- | + | ||
- | The OUTPUT_FILE parameter specifies the name of the MAT file to create. | + | |
- | * OUTPUT_SIGNAL_NAMES, | + | |
- | * MFILE_NAME specifies the name of the compiled Matlab function to run (this must be an .exe file). | + | |
- | * INPUT_FILE specifies the MAT file from which the processed data is imported | + | |
- | * INPUT_NAMES are the variable names (in the m-file) that are read. | + | |
- | * The processed data is placed in the signals specified by INPUT_SIGNAL_NAMES and INPUT_SIGNAL_TYPES (this data is considered " | + | |
- | + | ||
- | To clarify, the basic algorithm of the above CALL_MFILE command is illustrated below:\\ | + | |
- | + | ||
- | {{: | + | |
- | + | ||
- | + | ||
- | Note that, in order to pass the time signal to a MAT file, you should use " | + | |
==== Integrating Matlab dlls ==== | ==== Integrating Matlab dlls ==== | ||
Line 117: | Line 44: | ||
**The text file must have a .txt extension and the same name as the .dll it describes. An example would be:** | **The text file must have a .txt extension and the same name as the .dll it describes. An example would be:** | ||
- | |||
- | $ ls MathLab-Plugins # (or ' | ||
swindowlib.dll | swindowlib.dll | ||
swindowlib.txt | swindowlib.txt | ||
\\ | \\ | ||
- | |||
- | $ cat swindowlib.txt | ||
- | swindow | ||
- | / | ||
- | / | ||
- | / | ||
- | / | ||
- | ; | ||
**This tells Visual3D that swindowlib.dll has an entry point named swindo that takes 4 parameters: | **This tells Visual3D that swindowlib.dll has an entry point named swindo that takes 4 parameters: | ||
Line 334: | Line 251: | ||
===== Visual3D Pipeline Commands ===== | ===== Visual3D Pipeline Commands ===== | ||
- | + | Common pipeline commands used with Matlab' | |
- | === Call_MFile === | + | *[[visual3d: |
- | + | | |
- | Exports signals to an MFile routine, and imports results back to Visual3D. See [[# | + | *[[visual3d: |
- | + | *[[visual3d: | |
- | < | + | *[[visual3d:documentation:pipeline:pipeline_commands: |
- | Call_MFile | + | *[[visual3d:documentation:pipeline:file_commands:export_data_to_matlab|Export_Data_To_Matlab]] |
- | ! / | + | *[[visual3d: |
- | ! / | + | *[[visual3d: |
- | ! / | + | |
- | ! / | + | |
- | / | + | |
- | / | + | |
- | ! / | + | |
- | / | + | |
- | ! / | + | |
- | / | + | |
- | / | + | |
- | / | + | |
- | / | + | |
- | ! / | + | |
- | ! / | + | |
- | ! / | + | |
- | ; | + | |
- | </ | + | |
- | + | ||
- | === Import_Data_From_Matfile === | + | |
- | + | ||
- | Imports specified signals from a Matfile. | + | |
- | + | ||
- | < | + | |
- | Import_Data_From_Matfile | + | |
- | / | + | |
- | !/ | + | |
- | / | + | |
- | / | + | |
- | / | + | |
- | ; | + | |
- | </ | + | |
- | + | ||
- | This function expects the .mat file to have a specific input. For example, within MATLAB, we write and run the following script: | + | |
- | + | ||
- | < | + | |
- | array = linspace(0, | + | |
- | importThisData = {sin(array)}; | + | |
- | + | ||
- | FRAME_RATE{1, | + | |
- | ANALOG_VIDEO_FRAME_RATIO{1, | + | |
- | FILE_PATH = {'C:\Users\Public\MATLAB\Sub01_Walk001.c3d' | + | |
- | + | ||
- | matDirectory = 'C:\Users\Public\MATLAB\Sub01_Walk001.mat'; | + | |
- | save(matDirectory,' | + | |
- | </ | + | |
- | + | ||
- | What is really important is the FILE_PATH. Within your Visual3D workspace, you will presumably have loaded some .c3d files (in this case, Sub01_Walk001.c3d). The address under FILE_PATH must match the location of the original .c3d files, even if that path is different from the path of the Visual3D workspace. If the Import_Data_From_Matfile command executes but doesn' | + | |
- | + | ||
- | FILE_PATH is different from FILE_NAME, which should be the path to the .mat file you wish to import data from. | + | |
- | + | ||
- | === Export_Data_To_Matfile === | + | |
- | + | ||
- | This command is similar to [[# | + | |
- | + | ||
- | {{: | + | |
- | + | ||
- | It is very important to note that Visual3D expresses an unknown value (e.g. a TARGET with residual of -1) using the value DATA_NOT_FOUND (-99999). Matlab doesn' | + | |
- | + | ||
- | < | + | |
- | Export_Data_To_Matfile | + | |
- | ! / | + | |
- | ! / | + | |
- | ! / | + | |
- | ! / | + | |
- | / | + | |
- | ! / | + | |
- | ! / | + | |
- | ! / | + | |
- | ! / | + | |
- | ; | + | |
- | </ | + | |
- | + | ||
- | === Get_From_Matlab === | + | |
- | + | ||
- | Uses DCOM to put data from one active file in the Visual3D Workspace into Matlab (e.g. with Matlab running concurrently). | + | |
- | + | ||
- | < | + | |
- | Get_From_Matlab | + | |
- | / | + | |
- | / | + | |
- | / | + | |
- | / | + | |
- | ; | + | |
- | </ | + | |
- | + | ||
- | In Matlab the signal should appear with the Matlab_Item_Name. This is necessary because Matlab does not allow multiple signals with the same name but with a different type. | + | |
- | + | ||
- | === Put_To_Matlab === | + | |
- | + | ||
- | Uses DCOM to put data from one active file in the Visual3D Workspace into Matlab (e.g. with Matlab running concurrently). | + | |
- | + | ||
- | < | + | |
- | Put_To_Matlab | + | |
- | / | + | |
- | / | + | |
- | / | + | |
- | / | + | |
- | ; | + | |
- | </ | + | |
- | + | ||
- | In Matlab the signal will appear with the Matlab_Item_Name. This is necessary because Matlab does not allow multiple signals with the same name but with a different type. | + | |
- | + | ||
- | === Export_Data_To_Matlab === | + | |
- | + | ||
- | **THIS COMMAND DOES NOT WORK IN ANY VERSION OF MATLAB NEWER THAN Matlab R13. Use the [[# | + | |
- | + | ||
- | Visual3D will use DCOM to push signal directly in the Matlab Workspace without having to save the m-file. This command is different from [[# | + | |
- | + | ||
- | + | ||
- | **Export_Data_To_Matlab** | + | |
- | + | ||
- | |**/ | + | |
- | |**/ | + | |
- | |**/ | + | |
- | |**/ | + | |
- | |**/ | + | |
- | |**/ | + | |
- | |**/ | + | |
- | |**/ | + | |
- | |**/ | + | |
- | + | ||
- | + | ||
- | For example, export 3 TARGETS (LFT1, LFT2, LFT3) from Visual3D to Matlab. | + | |
- | + | ||
- | Invoke the Pipeline Edit Dialog | + | |
- | + | ||
- | {{:Export_Data_To_Matlab_Dlg1.gif? | + | |
- | + | ||
- | + | ||
- | Add the name of the Matlab struct array and the first TARGET. Select the Add Data button | + | |
- | + | ||
- | {{:Export_Data_To_Matlab_Dlg2.gif? | + | |
- | + | ||
- | + | ||
- | Add the remaining 2 signals | + | |
- | + | ||
- | {{: | + | |
- | + | ||
- | + | ||
- | The text version of the pipeline | + | |
- | + | ||
- | **Export_Data_To_Matlab** | + | |
- | + | ||
- | |**/ | + | |
- | |**/ | + | |
- | |**/ | + | |
- | |**/ | + | |
- | |**/ | + | |
- | |**/ | + | |
- | |**/ | + | |
- | |**/ | + | |
- | |**/ | + | |
- | + | ||
- | + | ||
- | + | ||
- | Execute the command with 4 active files in the Visual3D Workspace.\\ | + | |
- | + | ||
- | + | ||
- | Matlab should contain the following struct_array | + | |
- | + | ||
- | » TEST | + | |
- | + | ||
- | TEST = | + | |
- | + | ||
- | ANALOG_VIDEO_FRAME_RATIO: {4x1 cell} | + | |
- | FRAME_RATE: {4x1 cell} | + | |
- | FILE_NAME: {4x1 cell} | + | |
- | O_LFT1: {4x1 cell} | + | |
- | O_LFT2: {4x1 cell} | + | |
- | O_LFT3: {4x1 cell} | + | |
- | \\ | + | |
- | + | ||
- | + | ||
- | » TEST.O_LFT1 | + | |
- | + | ||
- | ans = | + | |
- | + | ||
- | [230x5 double] | + | |
- | [231x5 double] | + | |
- | [220x5 double] | + | |
- | [211x5 double] | + | |
- | === Import_Data_From_Matlab === | + | |
- | + | ||
- | Visual3D will use DCOM to pull signals directly from the Matlab Workspace without having to save the m-file. This command is different from [[# | + | |
- | + | ||
- | + | ||
- | **Import_Data_From_Matlab** | + | |
- | + | ||
- | |**/ | + | |
- | | | | | + | |
- | |**/ | + | |
- | | | | | + | |
- | |**/ | + | |
- | | | | | + | |
- | |**/ | + | |
- | | | | | + | |
- | |**/ | + | |
- | | | | | + | |
- | + | ||
- | \\ | + | |
- | + | ||
- | + | ||
- | {{: | + | |
- | + | ||
- | === Eval_In_Matlab === | + | |
- | + | ||
- | Causes a concurrent version of Matlab to execute the specified Matlab function. | + | |
Line 566: | Line 277: | ||
This sample code [[Visual3D: | This sample code [[Visual3D: | ||
- | === Exporting signals to a Matlab .mat file === | ||
- | |||
- | A useful function of the Visual 3D scripting language is its ability to communicate with Matlab, a programming language specifically designed for technical computing. | ||
- | |||
- | Data can be exported from Visual 3D to a MAT file by using the **Export_Data_To_Matfile** command. This command allows you to save signal data and parameter data from Visual 3D into MAT format so it can be read by a Matlab function. You must specify the file name of the file from which the data is to be taken, the signal name, the signal type, whether or not the signal is processed or not, and the output name. The output name is simply the name of the variable that is saved in the MAT file; this is not necessarily the same as the signal name (see below). In addition to this, if you want to export parameters (data from the PARAMETERS branch of the data tree), you can include the **PARAMETER_GROUPS, | ||
- | |||
- | As an example, Visual3D will export data to Matlab (.mat) files using the following pipeline command syntax. This example was derived using the ExampleWalk.c3d file available on the website. | ||
- | |||
- | Export_Data_To_Matfile | ||
- | / | ||
- | / | ||
- | / | ||
- | / | ||
- | / | ||
- | ! / | ||
- | ! / | ||
- | ! / | ||
- | ; | ||
- | |||
- | Note that Matlab 7.0 Release 14 is incompatible with Release 12 and 13; Visual3D currently import/ | ||
=== Matlab Cell Array === | === Matlab Cell Array === | ||
Line 591: | Line 282: | ||
Visual3D exports signals to a mat file as [[https:// | Visual3D exports signals to a mat file as [[https:// | ||
- | For example, the following command:// | + | For example, the following command: |
+ | < | ||
Export_Data_To_Matfile | Export_Data_To_Matfile | ||
/ | / | ||
Line 603: | Line 294: | ||
! / | ! / | ||
; | ; | ||
- | + | </ | |
- | places | + | Places |
RANK contains the contents of the signal RANKLE_ANGLE// | RANK contains the contents of the signal RANKLE_ANGLE// | ||
Line 625: | Line 316: | ||
Data can be imported to Visual3D using a syntax similar to export.// | Data can be imported to Visual3D using a syntax similar to export.// | ||
+ | < | ||
Import_Data_From_Matfile | Import_Data_From_Matfile | ||
FILE_NAME=**c: | FILE_NAME=**c: | ||
Line 633: | Line 324: | ||
INPUT_NAMES=**RFT1+RFT2+RFT3+FZ2+EMG9 | INPUT_NAMES=**RFT1+RFT2+RFT3+FZ2+EMG9 | ||
; | ; | ||
- | | + | </ |
=== Format of the mat file for Visual3D === | === Format of the mat file for Visual3D === | ||
- | The format of the matfile is specific to Visual3D. The following example demonstrates a simple use of the mat file that reveals the particular syntax expected by Visual3D. | + | The format of the matfile is specific to Visual3D. The following example demonstrates a simple use of the mat file that reveals the particular syntax expected by Visual3D.// |
+ | Edit average_3targets_return_target.m and add the following code:// | ||
< | < | ||
- | ! --------------------------------------------------------------------- | ||
- | ! The example m-file is listed here. | ||
- | ! To compile the m-file | ||
- | ! Switch to dos (Command Prompt) | ||
- | ! Change to directory containing the m-file | ||
- | ! To create the executable | ||
- | ! mcc -p average_3targets_return_target | ||
- | ! | ||
- | ! edit average_3targets_return_target.m | ||
- | ! and add the following code | ||
- | ! --------------------------------------------------------------------- | ||
function testmfile | function testmfile | ||
% load the file that was written out by C-Motion Visual3D | % load the file that was written out by C-Motion Visual3D |
visual3d/documentation/third-party/matlab/matlab.1756907125.txt.gz · Last modified: 2025/09/03 13:45 by wikisysop