User Tools

Site Tools


visual3d:documentation:third-party:matlab:matlab

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
visual3d:documentation:third-party:matlab:matlab [2025/09/03 19:56] wikisysopvisual3d:documentation:third-party:matlab:matlab [2025/09/18 15:22] (current) – [Examples] wikisysop
Line 44: 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 'dir' if you are a DOS person) 
 swindowlib.dll swindowlib.dll
 swindowlib.txt swindowlib.txt
 \\ \\
  
- 
-$ cat swindowlib.txt 
-swindow 
-/SIGNAL%%__%%IN%%__%%SIGIN 
-/INT%%__%%IN%%__%%WINSIZE 
-/INT%%__%%IN%%__%%WINSTEP 
-/SIGNAL%%__%%OUT%%__%%SIGOUT 
-; 
 **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 263: Line 253:
 Common pipeline commands used with Matlab's integration: Common pipeline commands used with Matlab's integration:
   *[[visual3d:documentation:pipeline:file_commands:call_mfile|Call_MFile]]   *[[visual3d:documentation:pipeline:file_commands:call_mfile|Call_MFile]]
- +  *[[visual3d:documentation:pipeline:file_commands:import_data_from_matfile|Import_data_from_matfile]] 
- +  *[[visual3d:documentation:pipeline:file_commands:export_data_from_matfile|Export_data_from_matfile]] 
- +  *[[visual3d:documentation:pipeline:pipeline_commands:get_from_matlab|Get_from_matlab]] 
-=== Import_Data_From_Matfile === +  *[[visual3d:documentation:pipeline:pipeline_commands:put_to_matlab|Put_To_Matlab]] 
- +  *[[visual3d:documentation:pipeline:file_commands:export_data_to_matlab|Export_Data_To_Matlab]] 
-Imports specified signals from a Matfile. +  *[[visual3d:documentation:pipeline:file_commands:import_data_from_matlab|Import_Data_From_Matlab]
- +  *[[visual3d:documentation:pipeline:metric_commands:eval_in_matlab|Eval_In_Matlab]]
-<code> +
-Import_Data_From_Matfile +
-/SIGNAL_TYPES= +
-!/SIGNAL_FOLDER=PROCESSED +
-/SIGNAL_NAMES= +
-/FILE_NAME= +
-/MATLAB_NAMES= +
-+
-</code> +
- +
-This function expects the .mat file to have a specific input. For example, within MATLAB, we write and run the following script: +
- +
-<code> +
-array = linspace(0,10,100); +
-importThisData = {sin(array)}; +
- +
-FRAME_RATE{1,1} = 180; +
-ANALOG_VIDEO_FRAME_RATIO{1,1} = 0; +
-FILE_PATH = {'C:\Users\Public\MATLAB\Sub01_Walk001.c3d'}; +
- +
-matDirectory = 'C:\Users\Public\MATLAB\Sub01_Walk001.mat'; +
-save(matDirectory,'importThisData','FILE_PATH','FRAME_RATE','ANALOG_VIDEO_FRAME_RATIO','-v6'+
-</code> +
- +
-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't create or populate a folder in the Visual3D workspace, check the FILE_PATH. +
- +
-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 [[#Export_Data_To_Matlab|Export_Data_To_Matlab]] except that the resulting data is placed in an Matlab .mat file rather than being pushed into the Matlab Workspace +
- +
-{{:export_data_to_matfile.png?600}} +
- +
-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't recognize this Visual3D expression, so you may want to replace DATA_NOT_FOUND with NaN (e.g. /USE_NAN_FOR_DATANOTFOUND=TRUE). If you don't and you list the contents of the variable in Matlab, your data may be scaled to 1.e5, which means that most of your values may end up looking as if they were zero. If you enter DATA_NOT_FOUND, you can have your m-file search for this value, so that you can continue to perform matrix math in Matlab (which won't process NaN in an array). Text version below: +
- +
-<code> +
-Export_Data_To_Matfile +
-! /SIGNAL_TYPES= +
-! /SIGNAL_FOLDER= +
-! /SIGNAL_NAMES= +
-! /FILE_NAME= +
-/MATLAB_NAMES= +
-! /PARAMETER_NAMES= +
-! /PARAMETER_GROUPS= +
-! /OUTPUT_PARAMETER_NAMES= +
-! /USE_NAN_FOR_DATANOTFOUND=FALSE +
-+
-</code> +
- +
-=== Get_From_Matlab === +
- +
-Uses DCOM to put data from one active file in the Visual3D Workspace into Matlab (e.g. with Matlab running concurrently). +
- +
-<code> +
-Get_From_Matlab +
-/Matlab_Item_Name= the name of the signal in Matlab +
-/Signal_Types= the Visual3D Type +
-/Signal_Names= the Visual3D Name +
-/Signal_Folder= the Visual3D Folder +
-+
-</code> +
- +
-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). +
- +
-<code> +
-Put_To_Matlab +
-/Matlab_Item_Name= the name of the signal in Matlab +
-/Signal_Types= the Visual3D Type +
-/Signal_Names= the Visual3D Name +
-/Signal_Folder= the Visual3D Folder +
-+
-</code> +
- +
-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 [[#Export_Data_To_Matfile|Export_Data_To_Matfile]] command instead** +
- +
-Visual3D will use DCOM to push signal directly in the Matlab Workspace without having to save the m-file. This command is different from [[#Put_To_Matlab|Put_To_Matlabe]] because it allows the data to be exported from all ACTIVE_FILES. This is possible because it uses a Matlab struct_array to store the data.\\ +
- +
- +
-**Export_Data_To_Matlab** +
- +
-|/MATLAB_ITEM_NAME=       |the name of the struct_array in Matlab                 | +
-|/SIGNAL_TYPES=            |the Visual3D Types                                     | +
-|/SIGNAL_NAMES=            |the Visual3D Names                                     | +
-|/SIGNAL_FOLDER=           |the Visual3D Folders                                   | +
-|/OUTPUT_NAMES=            |the names of the signal within the struct array        | +
-|/PARAMETER_GROUPS         |the C3D Parameter Group                                | +
-|/PARAMETER_NAMES=         |the C3D Parameter Name                                 | +
-|/OUTPUT_PARAMETER_NAMES=  |the Matlab name for the C3D Parameter                  | +
-|/USE_NAN_FOR_DATANOTFOUND=|DATANOTFOUND is the Visual3D name for a missing signal.| +
- +
- +
-For example, export 3 TARGETS (LFT1, LFT2, LFT3) from Visual3D to Matlab. +
- +
-Invoke the Pipeline Edit Dialog +
- +
-{{:Export_Data_To_Matlab_Dlg1.gif?600}}\\ +
- +
- +
-Add the name of the Matlab struct array and the first TARGET. Select the Add Data button +
- +
-{{:Export_Data_To_Matlab_Dlg2.gif?600}}\\ +
- +
- +
-Add the remaining 2 signals +
- +
-{{:Export_Data_To_Matlab_Dlg3.gif?600}}\\ +
- +
- +
-The text version of the pipeline command should look like this+
- +
-**Export_Data_To_Matlab** +
- +
-|/MATLAB_ITEM_NAME=          |TEST                      | +
-|/SIGNAL_TYPES=              |TARGET+TARGET+TARGET      | +
-|/SIGNAL_NAMES=              |LFT1+LFT2+LFT3            | +
-|/SIGNAL_FOLDER=             |ORIGINAL+ORIGINAL+ORIGINAL| +
-|/OUTPUT_NAMES=              |O_LFT1+O_LFT2+O_LFT3      | +
-|/PARAMETER_GROUPS                                    | +
-|/PARAMETER_NAMES=                                    | +
-|/OUTPUT_PARAMETER_NAMES=    |                          | +
-|/USE_NAN_FOR_DATA_NOT_FOUND=|TRUE                      | +
- +
- +
- +
-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 [[#Get_From_Matlab|Get_From_Matlab]] because it allows the data to be imported to multiple files. This is possible because it uses a Matlab struct_array to store the data.\\ +
- +
- +
-**Import_Data_From_Matlab** +
- +
-|/MATLAB_ITEM_NAME=|the name of the Matlab struct_array            | +
-|                      |                                               | +
-|/SIGNAL_TYPES=    |the Visual3D Types                             | +
-|                      |                                               | +
-|/SIGNAL_NAMES=   |the Visual3D Names                             | +
-|                      |                                               | +
-|/SIGNAL_FOLDER=   |the Visual3D Folders                           | +
-|                      |                                               | +
-|/INPUT_NAMES=     |the names of the signal within the struct array| +
-|                      |                                               | +
- +
-\\ +
- +
- +
-{{:Import_Data_From_Matlab_Dlg.gif?600}} +
- +
-=== Eval_In_Matlab === +
- +
-Causes a concurrent version of Matlab to execute the specified Matlab function.+
  
  
Line 472: Line 277:
  
 This sample code [[Visual3D:Documentation:Third-Party:MATLAB:Matlab_Read_V3D_Text|Matlab_Read_V3D_Txt]] can be used to read a text file exported from Visual3D into Matlab.\\ This sample code [[Visual3D:Documentation:Third-Party:MATLAB:Matlab_Read_V3D_Text|Matlab_Read_V3D_Txt]] can be used to read a text file exported from Visual3D into Matlab.\\
-=== 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, PARAMETER_NAMES, and OUTPUT_PARAMETER_NAME.** 
- 
-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 
-  /FILE_NAME=**c:demo filesMatlabtestmat.mat 
-  /SIGNAL_TYPES=**TARGET+TARGET+TARGET+ANALOG+ANALOG 
-  /SIGNAL_NAMES=**RFT1+RFT2+RFT3+FZ2+EMG9 
-  /SIGNAL_FOLDER=**ORIGINAL+ORIGINAL+ORIGINAL+ORIGINAL+ORIGINAL 
-  /OUTPUT_NAMES=**RFT1+RFT2+RFT3+FZ2+EMG9 
-  ! /PARAMETER_NAMES=** 
-  ! /PARAMETER_GROUPS=** 
-  ! /OUTPUT_PARAMETER_NAMES=** 
-  ; 
- 
-Note that Matlab 7.0 Release 14 is incompatible with Release 12 and 13; Visual3D currently import/exports data for release 12 and 13.// 
  
 === Matlab Cell Array === === Matlab Cell Array ===
Line 497: Line 282:
 Visual3D exports signals to a mat file as [[https://blogs.mathworks.com/loren/2006/06/21/cell-arrays-and-their-contents/|cell arrays.]] Visual3D exports signals to a mat file as [[https://blogs.mathworks.com/loren/2006/06/21/cell-arrays-and-their-contents/|cell arrays.]]
  
-For example, the following command:// +For example, the following command: 
 +<code>
   Export_Data_To_Matfile   Export_Data_To_Matfile
   /FILE_NAME=**c:demo filesMatlabtestmat.mat   /FILE_NAME=**c:demo filesMatlabtestmat.mat
Line 509: Line 294:
   ! /OUTPUT_PARAMETER_NAMES=   ! /OUTPUT_PARAMETER_NAMES=
   ;   ;
- +</code> 
-places 4 cell arrays into the matfile.//+Places 4 cell arrays into the matfile.//
  
 RANK contains the contents of the signal RANKLE_ANGLE// RANK contains the contents of the signal RANKLE_ANGLE//
Line 531: 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.//
 +<code>
   Import_Data_From_Matfile   Import_Data_From_Matfile
   FILE_NAME=**c:\demo files\Matlab\testmat.mat   FILE_NAME=**c:\demo files\Matlab\testmat.mat
Line 539: Line 324:
   INPUT_NAMES=**RFT1+RFT2+RFT3+FZ2+EMG9   INPUT_NAMES=**RFT1+RFT2+RFT3+FZ2+EMG9
   ;   ;
-  +</code>
 === 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://
  
 <code> <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.1756929419.txt.gz · Last modified: 2025/09/03 19:56 by wikisysop