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
 All Forums
 Origin Forum
 Origin Forum
 zeroing

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
juannim Posted - 02/15/2007 : 10:19:43 AM
Origin Version (Select Help-->About Origin): 7.5 pro
Operating System: xp

I have worksheets, each of which consists of 46 columns. The first column needs to stay in the worksheet, but I don't want to anything further with it. I want to zero the data in each of the remaining columns individually (subtract the minimum value in that column from each data point in that column), then export the 45 zeroed columns to a single CSV ascii file. I'd love to be able to write the script myself, but I am not there yet. Jonathan
15   L A T E S T    R E P L I E S    (Newest First)
juannim Posted - 03/23/2007 : 2:28:09 PM
That did it. Thanks so much. Jonathan
Mike Buess Posted - 03/23/2007 : 2:23:55 PM
Sorry, I forgot that Deanna suggested running the script from the Worksheet Script dialog. That sometimes behaves oddly and I can reproduce your results when I run the script from that dialog. So run it from the script window instead. Make sure the worksheet is on top, select all lines of the script and press enter. Alternately, you can copy the script to Custom.ogs like you tried before and run it from the Custom Routine button.

...In order to run the script successfully from the Worksheet Script dialog the loop command must be on one line.

loop(i,2,wks.ncols) {sum(%(%H,i)); %(%H,i) -= sum.min};

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 03/23/2007 2:30:22 PM
juannim Posted - 03/23/2007 : 12:24:20 PM
I have tried it on 3 different computers. None of them does anything to the data beyond removing the first column and saving a csv file. Here is a screensave of the original data, and the output (the excel file) Jonathan

Edited by - juannim on 03/23/2007 12:25:55 PM
Mike Buess Posted - 03/23/2007 : 12:04:25 PM
quote:
I want to subtract the smallest value in each column from every value in that column.
I've tried the same script several times and it always does exactly that.
quote:
I only have one worksheet in the project, so it must be active, yes?
A graph or matrix can also be active. The top window is active. Assuming that is the correct worksheet window I can't think of a reason for the script to fail. You might look at this...

http://www.originlab.com/www/support/resultstech.aspx?ID=1080&language=English

Mike Buess
Origin WebRing Member
juannim Posted - 03/23/2007 : 11:51:32 AM
I only have one worksheet in the project, so it must be active, yes? Jonathan
Mike Buess Posted - 03/23/2007 : 11:49:45 AM
quote:
I assume, however, that if I have some of the columns in that worksheet highlighted, then it is active.
Not necessarily. In the figure below Data3 is active even though columns are selected in Data2. The active worksheet is always on top. You said earlier that the script exports a file... Have you looked at that file to determine which worksheet was exported?



Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 03/23/2007 11:50:28 AM
juannim Posted - 03/23/2007 : 11:38:55 AM
here is the script that I am pasting:
loop(i,2,wks.ncols)
{
sum(%(%H,i));
%(%H,i) -= sum.min; // subtract minimum value of column
};
wo -s 0 0 0 0; // select all columns
wks.colSel(1,0); // deselect first column
wks.export.cntrl=8; // export selected columns
wks.export.separator$=","; // comma separated
getsavename *.csv; // get file name (%A)
save -wh %H %A; // export to %A

I want to subtract the smallest value in each column from every value in that column. So, I would expect to see a zero at some point in each column where the minimum value subtracts from itself, yes? The only possible screw-up that I can think of is that I don't have the worksheet "active". I assume, however, that if I have some of the columns in that worksheet highlighted, then it is active. Jonathan
Mike Buess Posted - 03/23/2007 : 11:26:24 AM
Perhaps your definition of "minimum value" differs from ours. We take it to mean the smallest value in the column. Do you mean something else? In any case, please paste your script to your reply.

Mike Buess
Origin WebRing Member
juannim Posted - 03/23/2007 : 10:47:22 AM
I still can't get it to subtract out the minimum value in each column. What am I doing wrong? I followed Deanna's directions. Jonathan
Deanna Posted - 03/23/2007 : 02:23:36 AM
Hi Jonathan.

I tried Mike's code. It does "zero" all the columns except the first one, and sucessfully exports the zerod columns as a CSV file.

Would you please try the following procedure?
1. Make sure that the workbook that has the data is active.

2. From Origin menu, choose Tools: Worksheet Script to open the Worksheet Script Window.

3. Copy the following script into the Worksheet Script Window.

loop(i,2,wks.ncols)
{
sum(%(%H,i));
%(%H,i) -= sum.min; // subtract minimum value of column
};
wo -s 0 0 0 0; // select all columns
wks.colSel(1,0); // deselect first column
wks.export.cntrl=8; // export selected columns
wks.export.separator$=","; // comma separated
getsavename *.csv; // get file name (%A)
save -wh %H %A; // export to %A

4. Click Do It button.

5. The "Save As" dialog box should be opened. Browse to the folder where you want to save the CSV file and name the CSV file in the File Name textbox. Click Save.

This should be able to save the zeroed columns. If problem persists, please tell us.

Deanna
OriginLab Technical Services
zachary_origin Posted - 03/23/2007 : 02:10:32 AM
Mike's script works fine for me...

Copy the LabTalk script to Script Window, highlight all the lines and press Enter...

Zachary
OriginLab Technical Services.

juannim Posted - 03/23/2007 : 01:29:51 AM
Mike,
I tried running that script in a worksheet script window, but no love. It exports a file, but doesn't zero. What am I doing wrong? J
Laurie Posted - 02/15/2007 : 3:54:07 PM
The Origin C method requires that you copy the code to a .C file and then first Build (compile and link), so that the function is available to you from LabTalk.

The main section of your OGS file, would then just call this function: subtract_and_export()

You could also programmatically compile and link the C file with the run.loadOC command. The main section of the Custom.ogs file would then be the following (assuming name of .C file is SubtractAndExport.c):


if( run.loadOC("SubtractAndExport.c") )
{
type -b "SubtractAndExport.c failed to load.";
return 1; // error
}
subtract_and_export;
return 0; // success

Since you're just starting out, you might want to choose the LabTalk method as there are fewer steps.

Laurie
OriginLab Technical Support
juannim Posted - 02/15/2007 : 3:18:01 PM
Mike,
I tried inserting the C function as the main so that I zero all the columns and export with a single click, but it doesn't seem to work. here's my screensave. What am I doing wrong?
Mike Buess Posted - 02/15/2007 : 12:36:35 PM
Hi Jonathan,

The LabTalk and Origin C solutions given below are nearly identical so take your pick.
// LabTalk method

loop(i,2,wks.ncols)
{
sum(%(%H,i));
%(%H,i) -= sum.min; // subtract minimum value of column
};
wo -s 0 0 0 0; // select all columns
wks.colSel(1,0); // deselect first column
wks.export.cntrl=8; // export selected columns
wks.export.separator$=","; // comma separated
getsavename *.csv; // get file name (%A)
save -wh %H %A; // export to %A


// Origin C method
void subtract_and_export()
{
Worksheet wks = Project.ActiveLayer();
for(int i=1;i<wks.GetNumCols();i++)
{
Dataset ds(wks,i);
ds -= min(ds); // subtract minimum value of column
}
wks.LT_execute("wo -s 0 0 0 0");
wks.LT_execute("wks.colSel(1,0)");
wks.GetPage().Refresh();
string strFile = GetSaveAsBox("*.csv"); // get file name
if( !strFile.IsEmpty() )
wks.ExportASCII(strFile, WKS_EXPORT_SELECTED, ',');
}


Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 02/15/2007 12:40:30 PM

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000