The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Matrix substraction + MatrixObject issues

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
ecerda Posted - 08/20/2010 : 10:57:52 AM
Origin Ver. and Service Release (Select Help-->About Origin): 8.1 SR3
Operating System: Windows XP

1st ISSUE:
I had a nice simple script to substract matrix A from matrix B and have the result in matrix A that worked fine with Origin 8.0:

void SubsMat(string mat1, string mat2)
{
Matrix mm1(mat1);
Matrix mm2(mat2);

mm1 = mm1 - mm2;
}

I do not know if something changed but it does not work with origin 8.1. Compiling is OK, but I get tghe infamous "Origin C Function Runtime Error, Calling members of unattached wrapper class" all the time. Any help please?

2nd ISSUE
2.1 How can I do batch operations (using foreach(MatrixObject mo...) ) like substracting a matrix from all the matrixobjects in a matrixpage? I get extract the data, pero somehow writing the data is not implemented

2.2 How can I add MatrixObjects using origin C?

thanks!

Edgar
5   L A T E S T    R E P L I E S    (Newest First)
ecerda Posted - 08/31/2010 : 12:13:39 PM
Dear Penn,

Thank you very much for your help. Your advice was very helpful.
Penn Posted - 08/24/2010 : 05:46:00 AM
Hi Edgar,

1. Maybe it is about the data type problem in your code. By default, the data type for a matrix is double, you have to make sure the matrix you are going to access is also with type of double. You can try the following code to see how this kind of error occurs.

void CreateMATRIX2(string winName, int nRows, int nCols)
{
	MatrixLayer mat;
	mat.Create(NULL,CREATE_HIDDEN);
	mat.GetPage().Rename(winName);
	mat.MatrixObjects(0).SetSize(nRows,nCols);
	
	string strName = mat.GetPage().GetName();
	//Matrix mm(strName); //--> Works fine
	Matrix<int> mm(strName); //==>Error, should be Matrix<double> type
	double matVal = mm[0][0];
}

Just create a new project, compile the code and then run CreateMATRIX2 aaa 2 3; in Script Window. By default, matrix is with double type, here I am using the int type, Matrix<int>. When the code is running to this line, the error you mentioned occurs, both "Calling members of unattached wrapper class" and "Warning, Data type mismatch". So, maybe you have to check whether there is data type mismatch in your code.

2. The method Insert I mentioned is not for insert/add MatrixLayer, but MatrixObject. The relationship among MatrixPage, MatrixLayer, and MatrixObject is just like the one among WorkBook, Worksheet, and Column. You can refer to this chapter of our User Guide.


Penn
ecerda Posted - 08/23/2010 : 12:07:34 PM

Some additional information: besides the "Calling members..." message, I get a "Warning, Data type mismatch" message in the

Matrix m1(MatName)

line, as if the matrix with name MatName were not a matrix...

thanks,

Edgar
ecerda Posted - 08/23/2010 : 11:43:57 AM
Dear Penn,

Thank you for your prompt answer. You are right, the code actually works fine but only on "normal" matrices; I tried it as well in other matrices and it was OK.

However, I think there is a problem regarding the way on which the matrices were generated, because it does not work on the ones I generate using the following procedure:

1. Import into a matrix an .h5 file using the standard origin function (the resulting matrixbook in my case has 49 matrixobjects)

2. Use a batch process to select a rectangle from the matrixobjects and send each to an individual matrix using the following script:

void RangeMatrix(int coli, int colf, int rowi, int rowf, int transp)
{
RECT rect; //Defines rectangle range in matrix
rect.left = coli;
rect.top = rowi;
rect.right = colf;
rect.bottom = rowf;

MatrixLayer ml1 = Project.ActiveLayer();

double ymin = 1239.856/ml1.Cell(rowi,0);// Get Y coordinate of ii-th row (arg is 0-based)
double ymax = 1239.856/ml1.Cell(rowf,0); // Get Y coordinate of ii-th row (arg is 0-based)
printf("Emin=%f , Emax=%f \n",ymin,ymax);

int ii=1;

string LayerName = ml1.GetPage().GetName();

foreach(MatrixObject mo in ml1.MatrixObjects)
{
string MatrixName = LayerName + ii;
int nCols = colf-coli; //Number of columns
int nRows = rowf-rowi; //Number of rows
CreateMATRIX2(MatrixName, nRows, nCols);

MatrixObject moResult(MatrixName, 0);

mo.CopyToMatrix(moResult, &rect);
moResult.SetXY(1, ymin, 10, ymax);

if(transp==1) mRes.Transpose();

printf("No. %d Copied \n ",ii);
ii++;
}

}


the code for the CreateMATRIX2(MatrixName, nRows, nCols) routine is:

void CreateMATRIX2(string winName, int nRows, int nCols)
{
MatrixLayer mat;
mat.Create(NULL,CREATE_HIDDEN);
mat.GetPage().Rename(winName);
mat.MatrixObjects(0).SetSize(nRows,nCols);
}


I get the range matrices OK, but when I use the command

Matrix m1(MatName) (-MatName is declared as a string-)

to define the matrix using the name of the matrixbook (in any script, including the one for substraction) I get the "Calling members of unattached wrapper class" message. Again, this only happens when I generate the matrices using my script. I do not know what the problem could be. I do not know what is "not normal" about these matrices...

2. Thanks for your help on this issues. I am a little confused though. The example you sent me is to insert a MatrixLayer, which, if I understood well, corresponds to a sheet in the workbook, each of which can have multiple matrixobjects. Is this correct?

Thank you very much!

Edgar
Penn Posted - 08/22/2010 : 11:24:46 PM
Hi Edgar,

1st issue:
I just make a simple try with your code, but can not reproduce it in Origin 8.1. My steps are:

1. Create two matrix books, named MBook1 and MBook2, then set their dimension to 2*2, and fill with some numbers into these cells.
2. After compiling the code, run SubsMat(MBook1, MBook2) in Script Window, that will get proper results and no error occurs.
So, could you please provide the steps on how to reproduce your problem?

2nd issue:
2.1 I have used the following code to do substraction, and then write the result back to the matrix object, all are implemented. You can have a try.

void MatrixLayer_MatrixObjects()
{
    MatrixPage mp = Project.MatrixPages( 0);  // first matrix book in the project
    if(!mp)
        return;
 
    MatrixLayer ml = mp.Layers( 0);  // get the first matrix layer in the matrix book
    
    MatrixObject mo1 = ml.MatrixObjects(-1);  // get the active matrix object
    matrix mat = mo1.GetDataObject();  // get data of the active matrix object
    
    foreach(MatrixObject mo in ml.MatrixObjects)  // loop all matrix objects
    {
    	matrix& matSrc = mo.GetDataObject();  // get data of matrix object, reference is used here
    	matSrc = matSrc-mat;  // substraction, write back to the matrix object
    }
}

2.2 There is a method for inserting and adding matrix objects to a matrix layer, please refer to Insert method.

Penn

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000