Author |
Topic  |
|
jaolson
Canada
3 Posts |
Posted - 04/25/2011 : 4:05:32 PM
|
Origin Ver. and Service Release OriginPro 8.5.0 SR1: Operating System: windows 7
I am trying to populate columns, say X and Y, from a column of values that I already have in my Origin worksheet. I am quite new to programming so please forgive my ignorance. the 'z' column contains values from 1-1681. x needs to range from 1 to 41 while y should be increase slowly so the last point is (41,41). the problem is that there may be repeating 'z' values, and the 'x' values need to also stay the same during this time.
this is what I have so far, but I am not sure how to link it to the column in my origin worksheet.
any advice would be greatly appreciated! cheers. jo.
int XYpopulate() { int x, y, z; for (x=1; x<41; x++){ for (y=1; y<41; y++){ while (z=ColumnA){ //columnA is the column in my worksheet I want to link to. writeValues(x, y); } } } } |
|
Penn
China
644 Posts |
Posted - 04/25/2011 : 11:18:17 PM
|
Hi jo,
I am not sure what your requirement is. The z column you mentioned is a known column with values, and then you want to fill values to the columns you said x column and y column, right? The x column should be filled from 1 to 41, and then repeat? How is y column increased slowly? What do you mean the repeating z values, two same values in z column?
Maybe you can represent your requirement with some simple data, and then I can see what resources are needed while programming.
Penn |
 |
|
jasmine_chan
China
Posts |
Posted - 04/26/2011 : 01:56:44 AM
|
Hi jo,
Here I show you how to change the column value in origin worksheet.
//---begin---
//this function will change the active worksheet's data
int XYpopulate2()
{
//attach to the active worksheet or create a new one
Worksheet wks = Project.ActiveLayer();
if( !wks.IsValid() )
{
wks.Create("origin");
if( !wks.IsValid() )
{
out_str("no worksheet");
return -1;
}
}
//set 3 columns to the worksheet
wks.SetSize(-1, 3, WSS_CLEAR_DATA|WSS_FILL_BLANK);
//first column: you can directly set value to it
int nRowSize = 20;
Dataset dsX;
dsX.Attach(wks, 0);
dsX.SetSize(nRowSize);
dsX = 100;
//second column: you can first set value to a vector and then pass the vector to the column
Dataset dsY(wks, 1);
vector vYValues;
vYValues.Data(1, nRowSize);
dsY = vYValues;
//third column: you can also set value to the cell of the column one by one
Dataset dsZ(wks, 2);
dsZ.SetSize(nRowSize);
vector vXValue;
vXValue = dsX;
for(int ii = 0; ii < nRowSize; ii++)
{
dsZ[ii] = vXValue[ii] - ii;
}
return 0;
}
//---end---
|
 |
|
jaolson
Canada
3 Posts |
Posted - 04/26/2011 : 09:52:04 AM
|
Hi Penn, thank you for the response. sorry my requirements were not very clear. yes you are right, x is from 1 to 41 and then repeat. a short section is shown below. notice how while z stays the same, x also does not increment, then when z increments, x also increments. so at the end of the data set, z = 1681 (41x41 grid),and x and y both = 41. thanks again for your help. jo
z x y 1 1 1 1 1 1 2 2 1 3 3 1 . . . . . . 41 41 1 41 41 1 42 1 2 . . .
quote: Originally posted by Penn
Hi jo,
I am not sure what your requirement is. The z column you mentioned is a known column with values, and then you want to fill values to the columns you said x column and y column, right? The x column should be filled from 1 to 41, and then repeat? How is y column increased slowly? What do you mean the repeating z values, two same values in z column?
Maybe you can represent your requirement with some simple data, and then I can see what resources are needed while programming.
Penn
|
 |
|
Penn
China
644 Posts |
Posted - 04/27/2011 : 02:24:46 AM
|
Hi jo,
Maybe the key problem is that you do not know how to fill values into a column. You can refer to jasmine_chan's reply on how to access column values. And you can also refer to the following example. However, please note that the algorithm for your issue may be not the best one, you'd better change to a better algorithm by yourself.
void XYpopulate()
{
// get the active worksheet
Worksheet wks = Project.ActiveLayer();
if(!wks)
return;
// suppose x, y, and z columns are column 1, 2, 3 respectively
Dataset dsX, dsY, dsZ;
dsX.Attach(wks, 0);
dsY.Attach(wks, 1);
dsZ.Attach(wks, 2);
dsX.SetSize(41*41);
dsY.SetSize(41*41);
dsZ.SetSize(41*41);
// fill x column
int iSize = 41*41;
int idx = 0;
for(idx=0; idx<iSize; idx++)
{
if(0==((int)dsZ[idx])%41)
{
dsX[idx] = 41;
}
else
{
dsX[idx] = ((int)dsZ[idx])%41;
}
}
// fill y column
int iY = 1;
for(idx=0; idx<iSize; idx++)
{
dsY[idx] = iY;
if(idx>0 && dsX[idx]==dsX[idx-1]-40)
{
iY++;
dsY[idx] = iY;
}
}
}
Penn |
 |
|
jaolson
Canada
3 Posts |
Posted - 04/27/2011 : 10:16:02 AM
|
Thanks for the help Penn and jasmine_chan. i appreciate it greatly. it gives me a good start and now hopefully i can meld the two codes together to make it work for me. again, thank you very much! |
Edited by - jaolson on 04/27/2011 10:16:28 AM |
 |
|
col54red
1 Posts |
Posted - 05/02/2011 : 12:21:30 PM
|
Actually i need this information too.
Thanks to Penn and Jasmine |
 |
|
nishikaj
USA
1 Posts |
Posted - 05/04/2011 : 4:25:22 PM
|
Thanks for this usefull info....... |
 |
|
NatalieJoy
Philippines
1 Posts |
Posted - 05/10/2011 : 01:26:01 AM
|
Penn's useful info has been a huge help. Thank you.
Natalie Mastura |
 |
|
|
Topic  |
|
|
|