Hi Isabelle,
In LabTalk, you can refer to matrix elements with two different commands:
Matrix1[i]=
or
cell(irow,icol)=
In the first case, the matrix is accessed as an 1D array so you need to compute the correct index for the (i,j)th cell. In the second case, you can directly refer to the cell you want to address. In this case the matrix window has to be active.
In either case, you will need to write a loop. Of course, as you mentioned, such loops are much faster in Origin C - up to a factor of 20 faster. If you look at the Matrix->Set Values dialog, there is an Origin C check box, which makes setting values faster.
You could try code like below to set your matrix values using Origin C. Compile this code, make the matrix window active, and type FillMat in the script window.
Also note that vector operations are possible as well - not necessary to always use loops.
For example, in LabTalk, you can set all values of a matrix to a constant or expression, set all values from a dataset, such as:
Matrix1 = sin(pi);
Matrix1 = Data1_B;
And in Origin C you can set all matrix values to constant or expression, and also set values in matrix from Dataset or Vector using the SetByVector method.
Easwar
OriginLab.
void FillMat()
{
MatrixLayer ml; // Declare OC MatrixLayer object
ml = (MatrixLayer) Project.ActiveLayer(); // Get active MatrixLayer from OC Project object
if(!ml.IsValid())
{
printf("Active page is not a matrix!\n"); // If active page is not a matrix, quit
return;
}
else
{
Matrix matA(ml); // Declare OC Matrix object
int iNumRows = matA.GetNumRows();
int iNumCols = matA.GetNumCols();
for(int ir = 0; ir < iNumRows; ir++)
for(int ic = 0; ic < iNumCols; ic++)
matA[ir][ic] = sin(ir)*cos(ic); // Fill values
}
}
Edited by - easwar on 10/31/2002 2:43:25 PM