Exporting Results
With LiveLink™ for MATLAB®, you can export data either to a text file by using the Export feature available in the model, or directly to the MATLAB workspace by using the COMSOL function suite available in MATLAB. See Extracting Results at the MATLAB® Command Line for more details.
Results can be exported to a text file by using the Export node.
1
data = model.result.export.create('data', 'Data');
data.setIndex('expr', 'T', 0);
2
Set the filename to <filepath>\Temperature.txt where <filepath> is replaced with the path to the directory where the file should be saved:
data.set('filename','<filepath>\Temperature.txt');
3
mphrun(model,'data');
The above steps extract the temperature at each computational node of the geometry and store the data in a text file in the following format:
% Model: Untitled.mph
% Version: COMSOL 6.3.0.250
% Date: Nov 1 2024, 15:08
% Dimension: 3
% Nodes: 1351
% Expressions: 1
% Description: Temperature
% Length unit: m
% X             Y               Z              T (K)
0.095           -0.02200000     0.06019615     323.47243290
0.095           -0.01803113     0.06159800     323.43024700
0.0975          -0.02023335     0.06305422     323.44003680
0.09767380      -0.01977740     0.05795373     323.49327862