| Author |
Topic  |
|
|
antekb
Poland
Posts |
Posted - 02/01/2007 : 10:31:45 AM
|
Origin Version :7.0 SR 2 Operating System:Windows XP
Hi Is there a method to copy rows from 1 to 40 and put it into a new column?
|
|
|
Mike Buess
USA
3037 Posts |
Posted - 02/01/2007 : 11:52:21 AM
|
This copies rows 1-40 from first column to a new column...
Worksheet wks = Project.ActiveLayer(); int iNew = wks.AddCol(); Dataset ds1(wks,0); Dataset ds2(wks,iNew); Data_copy(&ds2,&ds1,0,39)
Mike Buess Origin WebRing Member |
 |
|
|
antekb
Poland
Posts |
Posted - 02/02/2007 : 05:18:48 AM
|
hi thanks for help!! but.. I need it more...!!!! I tried to modify your code to move NEXT 40 rows into NEXT new column (and repeat this "a" times)
void move(int a) // "a" is a number of column { Worksheet wks = Project.ActiveLayer();
for (int i=0;i < a ;i++) { int iNew = wks.AddCol(); Dataset ds1(wks,i); Dataset ds2(wks,iNew); for (int k=0; k < a*40;k++) { Data_copy(&ds2,&ds1,k,k+39,-1);//(-1) = because I want //to move(old)row 40 to row 0 in new column and so on } } } This code works well, except that it just copy everything "a" times. To be precise: I try to make (a)columns, 40 rows each, from one column which is (a)*40 rows long
|
 |
|
|
Mike Buess
USA
3037 Posts |
Posted - 02/02/2007 : 08:18:46 AM
|
1. Your inner loop is wrong. You move rows 0-39, 1-40, 2-41, etc. rather than 0-39, 40-79, 80-119, etc. 2. nDestFrom=-1 means nDestFrom=nSrcFrom rather than nDestFrom=0. 3. You create and declare the new columns inside the wrong loop.
Try this...
for(int i=0; i<a; i++) { Dataset ds1(wks,i); for(int k=0; k<a*40; k+=40) { int iNew = wks.AddCol(); Dataset ds2(wks,iNew); Data_copy(&ds2,&ds1,k,k+39,0); } }
Mike Buess Origin WebRing Member
Edited by - Mike Buess on 02/02/2007 08:50:33 AM |
 |
|
|
antekb
Poland
Posts |
Posted - 02/05/2007 : 06:16:05 AM
|
Hi Mike Thanks for help The code works, but after first (a) columns has been copied (and this should terminate the loop) program copy first 40 rows to column (a+1), then rows 41 to 80 to column a+25 and so on(as a result of this error I get 552 additional columns). To be clear - source column in this notation would have (a-1)index.
With kind regards Antek |
 |
|
|
Mike Buess
USA
3037 Posts |
Posted - 02/05/2007 : 09:40:24 AM
|
Hi Antek,
Try this...
void copy_col() { Worksheet wks = Project.ActiveLayer(); int a = wks.GetNumCols(); for(int i=0; i<a; i++) { Dataset ds1(wks,i); for(int k=0; k<ds1.GetSize(); k+=40) { int iNew = wks.AddCol(); Dataset ds2(wks,iNew); Data_copy(&ds2,&ds1,k,k+39,0); } } }
Mike Buess Origin WebRing Member |
 |
|
|
antekb
Poland
Posts |
Posted - 02/06/2007 : 06:02:25 AM
|
Thanks Mike, it works very well I'm going to develop this further...
Best regards!! |
 |
|
|
antekb
Poland
Posts |
Posted - 02/06/2007 : 08:38:48 AM
|
Hi This time I need to: 1) normalize the data, which are output from the last code: so I have 25 columns, 40 rows each First column= original data, 2nd col = M0, remaining (a-1) columns is Mztau. To do normalization I need to calculate (M0-Mztau)/2*M0 for every (a-1) columns 2) put the result of this into new worksheet I tried to use the following example http://www.originlab.com/forum/topic.asp?TOPIC_ID=2378 So I got(of course it has no right to work!->only to show an idea): [code] void make(int b) { if(b < 1) { printf("incorrect column number specification!\n"); return; } Worksheet wks = Project.ActiveLayer(); int a = wks.GetNumCols(); for(int i=0; i<a; i++) { Dataset ds1(wks,i); for(int k=b+40; k<(ds1.GetSize()); k+=40) /* k=b+40 because these rows contains data I need later on */ { int iNew = wks.AddCol(); Dataset ds2(wks,iNew); Data_copy(&ds2,&ds1,k,k+39,0); } } /* end of part one*/ //////////////////////////////////////////////////////////////////////////////////////// Worksheet wksNormalized; wksNormalized.Create("Origin.otw") /* (1) what would be the name of this worksheet?? */
for( int c = 2; c < (b+1); c++) /*(c) should loop through columns that are to be normalised; c < (b+1) because first col is original (RAW) data, 2nd col contain M0 values (assuming RAW data col has index 0)*/ { int iSize = ds2.GetSize(); /*(2)here I want to "get" lenght of dataset ds2(should be 40 rows) - but it seems to me that every (b)'s column should be a separate dataset...how to do that? */ for(int iRow = 0; iRow < iSize; iRow++) { dsData[iRow] = ( ds2[iRow]-ds[iRow]/(2*ds2[iRow]) ; } /*normalizedData(in new=normalizedWKS) =(M0-Mztau)/2*M0{from part one}*/ } } Q: 3)How to refer to columns in a different worksheet?
|
 |
|
|
Mike Buess
USA
3037 Posts |
Posted - 02/06/2007 : 10:06:05 AM
|
1) This will get the name of new wks but I don't think you need it.
string wksNormalizedName = wksNormalized.GetPage().GetName();
2) At this point none of your datasets are declared so your Part 2 code won't work. Also, you don't need to calculate the normalized dataset one row at a time. Vector math is much faster. Also2, it doesn't look like you have enough columns in your new wks? By now I'm confused about what a, b and c mean (doesn't a=1?) but you can try this for Part 2...
Worksheet wksNormalized; wksNormalized.Create("Origin.otw"); for(int i=0; i<wksNormalized.GetNumCols(); i++) // delete existing columns { wksNormalized.DeleteCol(0); } Dataset ds2(wks,1); // MO? Dataset ds, dsData; // Mztau?, normalized? for( int c = 2; c < (b+1); c++) { int iCol = wksNormalized.AddCol(); ds.Attach(wks,c); dsData.Attach(wksNormalized,iCol); dsData = (ds2 - ds) / ds; // vector math }
Mike Buess Origin WebRing Member |
 |
|
|
antekb
Poland
Posts |
Posted - 02/07/2007 : 08:18:06 AM
|
Hi Mike Originally my data is a 2D array [t x tau] where t=40, tau=vary.It is
stored as single column (first few rows are labels-ASCII import procedure
just make them column label-they do not interrupt, next tau (b in script
code) rows are the values of time spacings between measurements; after that
there are t=40 rows containing time base of a single measurement.Last tau x
t(=40) rows contain amplitudes of all measurements.
I am sorry for this, but...
The problem I have just found is that normalization procedure requires that
the values of all rows from (b-1) columns should be calculated as follows:
((M0-Mz(t,tau))/2*M0) where M0 is a value stored in first row of first column->after part one. M0 is NOT a whole column, SORRY (Mea culpa..) !!
Worksheet wksNormalized; wksNormalized.Create("Origin.otw"); for(i=0; i<wksNormalized.GetNumCols(); i++) // delete existing columns { wksNormalized.DeleteCol(0); } Dataset ds2(wks,1); // MO= this should be single value instead of column so I'm afraid that vector math won't work here...How to refer to this value? Dataset ds, dsData; // Mz-tau-t, normalized for( int c = 2; c < (b+1); c++) { int iCol = wksNormalized.AddCol(); ds.Attach(wks,c); dsData.Attach(wksNormalized,iCol); dsData = (ds2 - ds) / (2*ds2); // vector math } }
|
 |
|
|
Mike Buess
USA
3037 Posts |
Posted - 02/07/2007 : 12:34:00 PM
|
But ds is still a dataset and you can operate on the whole dataset with a scalar.
Worksheet wksNormalized; wksNormalized.Create("Origin.otw"); for(i=0; i<wksNormalized.GetNumCols(); i++) // delete existing columns { wksNormalized.DeleteCol(0); }
Dataset ds, dsData; // Mz-tau-t, normalized double dMO = wks.Cell(0,0); // dMO is value at first row of first column for( int c = 2; c < (b+1); c++) { int iCol = wksNormalized.AddCol(); ds.Attach(wks,c); dsData.Attach(wksNormalized,iCol); dsData = (dMO - ds) / (2.0 * dMO); // vector math } }
Mike Buess Origin WebRing Member |
 |
|
| |
Topic  |
|
|
|