1.11.3 Exporting Matrices

An Origin Matrix can be exported to an ASCII data file or an image file.

Export Matrix to ASCII Data File

The following example shows how to export ASCII data from the active matrix window to a *.txt file. You need to add #include <oExtFile.h> for the export_matrix_ascii_data function.

file     ff;
if ( !ff.Open("C:\\ExpMatData.txt", file::modeCreate|file::modeWrite) )
    return; //fail to open file for write        

string 		strRange;
MatrixLayer ml = Project.ActiveLayer();

LPCSTR     		lpcszSep = "\t";
vector<string> 	vXLabels, vYLabels; // empty means no label

// return 0 for no error
int nErr = export_matrix_ascii_data(&ff, strRange, ml.GetNumRows(),
        ml.GetNumCols(), lpcszSep, &vXLabels, &vYLabels, dwCntrl);

Export Image from Matrix to Image File

The following example shows how to export a matrix to an image file.

Prior to running the following example, the image_utils.c file need to be loaded and compiled. This can be done from script with the following command or just add this file to your workspace.


And need to add #include <image_utils.h> for the export_Matrix_to_image function.

MatrixLayer ml = Project.ActiveLayer();
MatrixObject mo = ml.MatrixObjects();
export_Matrix_to_image("c:\\matrixImg.jpg", "jpg", mo);