Author |
Topic  |
|
jjaques1
USA
5 Posts |
Posted - 09/17/2002 : 11:48:05 AM
|
Hi, I am having a problem converting a worksheet into a matrix for 3D plotting (Origin 7, SP2). The worksheet has X values in the first column and Y values in the first row. The rest of the cells are filled with the Z values. Normally, I would do a Direct conversion to a matrix and then set the dimensions. However, my X and Y values are irregularly spaced. Is there a way to convert a worksheet like this into a matrix? Thanks.
-Jim
Edited by - jjaques1 on 09/17/2002 12:24:28 PM |
|
easwar
USA
1965 Posts |
Posted - 09/17/2002 : 4:01:13 PM
|
Hi,
Perhaps the best way is for you to convert the data from your present form to XYZ columns, and then use one of the random conversion methods. Ver 7 offers new methods based on the NAG library.
Try the code segment pasted here. Copy paste the code to a new file in Code Builder, compile the code, and then make your worksheet active and type the follwing in the script window: ConvertToXYZ
A new worksheet will be created, with three columns X,Y,Z. You can then highlight Z and then use the menu Edit->Convert to Matrix->Random XYZ which will bring up a dialog from which you can choose a conversion method.
Hope this helps.
Easwar OriginLab.
void ConvertToXYZ() { // Delcare a worksheet object for current active layer Worksheet wksData = Project.ActiveLayer();
// Check if active layer is a worksheet if(!wksData.IsValid()) { printf("Active window is not a worksheet!\n"); return; } // Get number of rows in worksheet int nR1, nR2; wksData.GetRange(nR1, nR2); int iNumRows = nR2 + 1; // Get number of columns in worksheet int iNumCols = wksData.Columns.Count(); // Create a new worksheet Worksheet wksXYZ; wksXYZ.Create(); // Add another column wksXYZ.AddCol(); // Set this col as Z wksXYZ.Columns(2).SetType(OKDATAOBJ_DESIGNATION_Z); // Now loop over all Z data and copy X,Y,Z to new worksheet for(int iR = 1; iR < iNumRows; iR++) { for(int iC = 1; iC < iNumCols; iC++) { // Compute destination row number int iRDest = (iNumCols - 1) * (iR - 1) + iC - 1; // Get X, Y, Z from source cells and copy to destination cells wksXYZ.SetCell(iRDest, 0, wksData.Cell(0, iC) ); wksXYZ.SetCell(iRDest, 1, wksData.Cell(iR, 0) ); wksXYZ.SetCell(iRDest, 2, wksData.Cell(iR, iC) ); } } }
|
 |
|
jjaques1
USA
5 Posts |
Posted - 09/18/2002 : 11:52:10 AM
|
Thanks. I will try that.
-Jim |
 |
|
baoqinan
USA
Posts |
Posted - 03/17/2004 : 12:02:48 PM
|
I still have problem with it. when i typed in ConvertToXYZ, it just give me Command Error! Can you explain it in more detail? And actually, when I try to compile the code, it did nothing. Should there show something when it was compiling?
quote:
Hi,
Perhaps the best way is for you to convert the data from your present form to XYZ columns, and then use one of the random conversion methods. Ver 7 offers new methods based on the NAG library.
Try the code segment pasted here. Copy paste the code to a new file in Code Builder, compile the code, and then make your worksheet active and type the follwing in the script window: ConvertToXYZ
A new worksheet will be created, with three columns X,Y,Z. You can then highlight Z and then use the menu Edit->Convert to Matrix->Random XYZ which will bring up a dialog from which you can choose a conversion method.
Hope this helps.
Easwar OriginLab.
void ConvertToXYZ() { // Delcare a worksheet object for current active layer Worksheet wksData = Project.ActiveLayer();
// Check if active layer is a worksheet if(!wksData.IsValid()) { printf("Active window is not a worksheet!\n"); return; } // Get number of rows in worksheet int nR1, nR2; wksData.GetRange(nR1, nR2); int iNumRows = nR2 + 1; // Get number of columns in worksheet int iNumCols = wksData.Columns.Count(); // Create a new worksheet Worksheet wksXYZ; wksXYZ.Create(); // Add another column wksXYZ.AddCol(); // Set this col as Z wksXYZ.Columns(2).SetType(OKDATAOBJ_DESIGNATION_Z); // Now loop over all Z data and copy X,Y,Z to new worksheet for(int iR = 1; iR < iNumRows; iR++) { for(int iC = 1; iC < iNumCols; iC++) { // Compute destination row number int iRDest = (iNumCols - 1) * (iR - 1) + iC - 1; // Get X, Y, Z from source cells and copy to destination cells wksXYZ.SetCell(iRDest, 0, wksData.Cell(0, iC) ); wksXYZ.SetCell(iRDest, 1, wksData.Cell(iR, 0) ); wksXYZ.SetCell(iRDest, 2, wksData.Cell(iR, iC) ); } } }
Edited by - baoqinan on 03/17/2004 12:04:42 PM
Edited by - baoqinan on 03/17/2004 12:05:25 PM |
 |
|
baoqinan
USA
Posts |
Posted - 03/17/2004 : 12:35:52 PM
|
Ok, it works now and I can plot the coutour plot But I can't use log sacle on coutour plot Is it possible that I can do that?
|
 |
|
easwar
USA
1965 Posts |
Posted - 03/17/2004 : 2:33:55 PM
|
Hi,
You can use log scale for the z axis/values in a contour plot, not for x and y axes.
To change the z values to log scale, bring up Plot Details dialog for the contour plot, click on the "Level" column header in the "Color Map/Contours" tab. This will bring up a dialog, in which you will see a "Log Scale" checkbox.
Easwar OriginLab.
|
 |
|
baoqinan
USA
Posts |
Posted - 03/17/2004 : 4:13:07 PM
|
Thank you for your answer. So it seems that we can't change x and y axes to log scales. Are there any other methods to do this?
quote:
Hi,
You can use log scale for the z axis/values in a contour plot, not for x and y axes.
To change the z values to log scale, bring up Plot Details dialog for the contour plot, click on the "Level" column header in the "Color Map/Contours" tab. This will bring up a dialog, in which you will see a "Log Scale" checkbox.
Easwar OriginLab.
|
 |
|
|
Topic  |
|
|
|