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
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Direct Conversion of Worksheet to Matrix
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

superman1

UK
6 Posts

Posted - 11/06/2002 :  09:20:57 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hello All,

What code do I use to convert a worksheet directly to a matrix?

thanks
Andrew

easwar

USA
1965 Posts

Posted - 11/06/2002 :  10:16:09 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Andrew,

If you want to do this from LabTalk, you can use code like below, where active window is assumed to be the worksheet to begin with:

mat.wksname$ = %H;
win -T M;
mat.matname$ = %H;
mat.w2m();

If you want to do this from Origin C, you can use code like below, where you will call this function passing the name of the worksheet to be converted.

 
void wks2mat(string strWksName)
{
Worksheet wks(strWksName); // Declare Worksheet
MatrixPage matPg; // Declare Matrix Page
matPg.Create("Matrix.OTP"); // Create Matrix Page using standard template
string strMatName = matPg.GetName(); // Get name of Matrix Page that was created
using mat = LabTalk.Mat; // Set up access to LabTalk mat object from Origin C
mat.wksname$ = strWksName; // Set name of worksheet in mat object
mat.matname$ = strMatName; // Set name of result matrix in mat object
mat.w2m(); // Use wkstomat conversion method of mat object
}


Easwar
OriginLab.
Go to Top of Page

superman1

UK
6 Posts

Posted - 11/06/2002 :  11:47:22 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks Easwar, I will try your code.

Why did you not use the following?

void copyfromwks()
{
// Assumes Data1 worksheet and Matrix1 matrix exist in Origin
Worksheet wks("Data1");
Matrix mat1("Matrix1");
BOOL bRet = false;
if(mat1 && wks)
bRet = mat1.CopyFromWks(wks); //Copies the whole wks to m1

}

It is the example code from the Programming Guide. It did not work for me.

Andrew

Go to Top of Page

easwar

USA
1965 Posts

Posted - 11/06/2002 :  1:46:08 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Andrew,

What you found in the documentation is much better than what I suggested. And it works fine.

Maybe you can debug the code and see why it is not working for you? The code assumes that worksheet Data1 and matrix Matrix1 already exist in your project. The if statement checks for validity of those objects and does the conversion only if they both exist. Maybe that is where you have the problem?

Easwar
OriginLab.



Edited by - easwar on 11/06/2002 1:49:08 PM
Go to Top of Page

superman1

UK
6 Posts

Posted - 11/07/2002 :  05:21:39 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Easwar,

Here is my code:


void portrait()
{

string ElecName = InputBox("Please enter the electrode to be ploted \n case sensitive");

Worksheet wks(ElecName);
string m=("m");
string MatName = lstrcat (ElecName, m);

MatrixPage matpg;
matpg.Create();
matpg.Rename(MatName);
Matrix mat;
mat.Attach(MatName);
mat.CopyFromWks(wks);


}

What I am trying to do is have a user enter the name of an existing orgin worksheet, then create a matrix with an m appended to the end of the name, and then directly convert the worksheet to the matrix.

Its not working!!

Any ideas? Thanks for all the help.
Andrew

Go to Top of Page

easwar

USA
1965 Posts

Posted - 11/07/2002 :  08:58:01 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Andrew,

Change the line
matpg.Create();
to
matpg.Create("Matrix.OTP");
which creates the matrix using the default Origin matrix template. Then it works fine.

Easwar
OriginLab.
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000