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 for Programming
 Forum for Origin C
 Normalizing a column

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
AbbyR Posted - 11/22/2014 : 9:20:45 PM
Origin Ver. and Service Release (Select Help-->About Origin):
Operating System:

I am trying to write a macro(using C) where I am importing an excel file into origin, deleting a coupe of unwanted columns and then plotting the data. I am able to do all of this, but now I need to normalize the values in a column. This has to be done by taking a number as input(float data type) from the user and then dividing the values in a particular column by this number. Could anybody help me out with how to divide a column by a constant(taken as an input from the user).

Thanks
2   L A T E S T    R E P L I E S    (Newest First)
AbbyR Posted - 12/02/2014 : 11:19:47 AM
That worked! Thanks a lot :)

cdrozdowski111 Posted - 11/23/2014 : 07:13:20 AM
Below is some example Origin C code that addresses both of your questions.
1) Provides an example of how to create a nice dialog box to accept a number entered by user.
2) Divides the values in a column by the number user entered.

It assumes you have an active worksheet with data in column 2.


#include <Origin.h>
#include <GetNbox.h>

// Function to create dialog box
// dNum parameter is passed by reference to function meaning its value can be changed in function
// Function returns true if user clicks OK in dialog and false if they cancel dialog
bool MyNumDialog(double& dNum)
{
	// Origin C macros to build custom dialog
	GETN_BOX(tr)
	GETN_NUM(dResult, "Enter a Value", dNum)	// "Enter a Value" is the label for the actual control. You can change this.

	// GetNBox() displays the dialog and returns true if user clicked OK and false if they canceled the dialog.
	// Change "Dialog Title" and "Description Text" to whatever you wish
	bool bRet = GetNBox(tr, "Dialog Title", "Description Text");

	// User clicked OK, so change the variable passed by reference to the function and return true
	// If control is empty and OK is clicked, the value is set to 0
	if (bRet)
		dNum = tr.dResult.dVal;

       // Return result of calling GetNBox() (true or false)
	return bRet;
}

void MyTestDlg()
{
	double dd; // Decimal variable to hold value to divide column by
	dd = 1.0; // You can set this to an initial value e.g. 1

	// Pass dd variable by reference to dialog function
	bool bOK = MyNumDialog(dd);
	if (bOK)
		printf("User entered: %f \n", dd);
	else
	{
		printf("User cancelled dialog");
		return;
	}

	// Make sure variable wasn't assigned 0- prevent divide by 0!
	if(is_equal(0, dd))
	{
		printf("User entered 0. Cannot divide by 0!!!");
		return;
	}

	// Assumes you have an active worksheet with data in columns 1 & 2
	Worksheet wks = Project.ActiveLayer();
	// Validate that there is an active worksheet
	if (!wks)
	{
		printf("No active worksheet");
		return;
	}
	
	// Dataset objects can be used to access column data
	// Cols are indexed starting with 0, so 1 is second column
	Dataset ds(wks, 1);
	// Validate that there is a column 2
	if (!ds)
	{
		printf("No Column 2");
		return;
	}
	
	// Here is the actual (and simple) code to divide the column by the number user entered.
	// It checks to see if there are values in column first
	if (ds.GetSize() > 0)
	    ds /= dd;
}

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