Author |
Topic |
|
JaapVerheggen
Ireland
Posts |
Posted - 01/04/2007 : 10:17:11 AM
|
Origin Version (Select Help-->About Origin): 7.5 SR6 Operating System: WINXP
I'd like to make a def that copies a single row from a matrix and adds it as a column to a worksheet. I'm having issues in obtaining the row, this is how far i got:
def takeline { //matrix identifier is %1, line identifier is %2, worksheet identifier is %3 //take row of matrix w = getrow(%1, %2); //add new column to worksheet and fill with data v = %3!wks.addCol(%1); copy w v; }
I am not sure if the take row of matrix is correct, the add new column to worksheet works, but to fill it with tha matrix data is not working.
Anybody any ideas about this? |
|
Mike Buess
USA
3037 Posts |
Posted - 01/04/2007 : 1:20:50 PM
|
getrow() is not a built-in LabTalk function so I don't know what it's supposed to do. Also, w and v are simple variable names which only represent a single value. Rather than trying to correct your macro I suggest you try the following simple Origin C function. Add it to CodeBuilder's workspace as described here and call it from LabTalk like this...
OC_takeline matrixName rowNumber wksName;void OC_takeline(string matName, int rowNum, string wksName) { Matrix mm(matName); if( !mm ) return; if( rowNum>mm.GetNumRows() ) return; Worksheet ww(wksName); if( !ww ) { ww.Create(); ww.GetPage().Rename(wksName); ww.DeleteCol(1); ww.DeleteCol(0); } int i = ww.AddCol(); ww.Columns(i).SetLabel("row: " + rowNum); ww.ShowLabels(); Dataset dd(ww,i); mm.GetRow(dd,rowNum-1); }
Mike Buess Origin WebRing Member |
|
|
JaapVerheggen
Ireland
Posts |
Posted - 01/05/2007 : 08:17:41 AM
|
It is working perfectly, thank you.
I've included the script altered to my personal preferences and some (helpful) comments for anybody who is interested.
void OC_takeline(string matName, int rowNum, string wksName) { Matrix mm(matName); //Define matrix if( !mm ) return; //if matrix doesn't exist if( rowNum>mm.GetNumRows() ) return; //If the row number doesn't exist Worksheet ww(wksName); //Define worksheet if( !ww ) //if worksheet doesn't exist, create one { ww.Create(); ww.GetPage().Rename(wksName); ww.DeleteCol(1); //Delete B(Y), but keep A(X) } int i = ww.AddCol(matName); ww.Columns(i).SetLabel("row: "+rowNum); //Add column, name is matrix name, label is row number ww.ShowLabels(FALSE); //Hide label Dataset dd(ww,i); //Import line from matrix mm.GetRow(dd,rowNum-1); }
---///---
Edited by - JaapVerheggen on 01/05/2007 08:32:07 AM |
|
|
thiago.maf
22 Posts |
Posted - 11/22/2010 : 07:34:14 AM
|
Hi.... Is that anyway to put this function in a loop that transfer a X number of lines to a same column (not new columns)?
|
|
|
thiago.maf
22 Posts |
Posted - 11/22/2010 : 07:40:47 AM
|
If one deal with i variable, its is possible to control (and fix it) in wich column the data will be putted. Therefore, the code overwrite the old data with the new one (from consecutive rows).
So, it's necessary to set a star row to distribute data along the column. Anyone could help me? |
|
|
thiago.maf
22 Posts |
Posted - 11/22/2010 : 07:43:26 AM
|
I promisse that is the last post.
I have this kind of data:
-209.8 -214.0 -216.2 -216.6 -215.0 -211.6 -206.1 -198.9 -190.2 -179.5 -167.4 -154.0 -139.3 -124.1 -107.7 -90.8 -73.9 -56.6 -39.7 -22.9 -6.7 8.6 22.9 35.9 47.7 58.1 66.7 73.7 78.9 82.4 84.0 83.9 82.3 78.9 74.0 67.7 60.2 51.7 42.3 32.4 21.9 11.3 0.7 -9.6 -19.4 -28.7 -37.0 -44.4 -50.6 -55.5 -59.0 -61.1 -61.6 -60.8 -58.4 -54.5 -49.4 -42.8 -35.3 -26.7 -17.2 -7.1 3.1 13.9 24.5 34.9 44.9 54.1 62.6 70.0 76.2 81.0 84.3 85.9 85.9 83.9 80.3 74.9 67.5 58.6 47.8 35.7 22.4 7.5 -8.4 -25.0 -42.6 -60.3 -78.5 -96.6 -113.9 -131.2 -147.6 -163.2 -177.5 -190.3
And need to do this:
-209,8 -214 -216,2 -216,6 -215 -211,6 -206,1 -198,9 -190,2 -179,5 -167,4 -154 -139,3 -124,1 -107,7 -90,8 -73,9 -56,6 -39,7 -22,9 -6,7 8,6 22,9 35,9 47,7 58,1 66,7 73,7 78,9 82,4 84 83,9 82,3 78,9 74 67,7 60,2 51,7 42,3 32,4 21,9 11,3 0,7 -9,6 -19,4 -28,7 -37 -44,4 -50,6 -55,5 -59 -61,1 -61,6 -60,8 -58,4 -54,5 -49,4 -42,8 -35,3 -26,7 -17,2 -7,1 3,1 13,9 24,5 34,9 44,9 54,1 62,6 70 76,2 81 84,3 85,9 85,9 83,9 80,3 74,9 67,5 58,6 47,8 35,7 22,4 7,5 -8,4 -25 -42,6 -60,3 -78,5 -96,6 -113,9 -131,2 -147,6 -163,2 -177,5 -190,3
|
|
|
greg
USA
1379 Posts |
Posted - 11/23/2010 : 3:08:22 PM
|
// How many rows get col(1) -e end; // How many columns to start with ncols = wks.ncols; // Add a column wo -a 1; // Output row iRow = 1; // For each row loop(ii,1,end) { // For each column loop(jj,1,wks.ncols) { wcol(wks.ncols)[iRow] = wcol(jj)[ii]; iRow++; } }
|
|
|
|
Topic |
|
|
|