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
 How to read data into worksheet

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
tony_lincoln Posted - 09/08/2006 : 11:12:25 PM
Dear friends,
I am learning Origin C now and really wonder how to read txt file into worksheet. Then I could do the curve fitting.
In my txt file, there are two float columns, one is x and one is y.
THanks.
Tony
6   L A T E S T    R E P L I E S    (Newest First)
tony_lincoln Posted - 09/10/2006 : 12:10:06 PM
Great, Thanks a lot, Mike.
Tony
Mike Buess Posted - 09/10/2006 : 07:57:49 AM
Best fit has the smallest chi-square value. It would be pointless to use nlsf.fit(1000000) because fitting stops when when chi-square ceases to change.

Mike Buess
Origin WebRing Member
tony_lincoln Posted - 09/09/2006 : 11:34:28 PM
Hi Mike,

Thanks a lot. But still one question here --- How to judge the goodness of fit.
The the codes that you wrote, its like:
NLSF.Fit(100);
Of course I can change it into
NLSF.Fit(1000000);
But the problem is, how do I know if it fitts well, and what is the goodness of fit.
Thanks a lot.

Tony
tony_lincoln Posted - 09/09/2006 : 10:40:02 PM
Great, it works in a perfect way. Thanks a lot, Mike!
Tony
Mike Buess Posted - 09/09/2006 : 1:36:41 PM
You'll find a useful example project in your program folder...

Samples\Programming\Automation\Automation.opj (Origin 7.0)
Samples\Programming\Automation\AutomationExample.opj (Origin 7.5)

Note that it's VERY useful to indicate your Origin version in the starting post of a topic.

Mike Buess
Origin WebRing Member
Mike Buess Posted - 09/09/2006 : 12:42:47 AM
Hi Tony,

The following code imports, plots and fits a *.txt file. Import and plot code is based on an example from here. Fitting code is based on what you posted here.
void simple_import_and_fit()
{
// Bring up file dialog for user to select the file.
// Replace *.txt with your desired extension as needed.
string strFile = GetOpenBox("*.txt");
if( strFile.IsEmpty() )
{
out_str("No file was selected!");
return;
}

// Create a new worksheet
Worksheet wks;
// If you wish to use a custom worksheet template, then specify the name of
// your template in place of Origin.OTW
wks.Create("Origin.OTW");
// Import the file into the worksheet using the current ASCIMP
// (Import ASCII Options) stored in the worksheet.
// You can edit the ASCIMP options from the GUI and save it back to
// the worksheet and then save the worksheet as a custom template.
// You can then create a new instance of your custom template and use it
// to import the data next time.
BOOL bRet = wks.ImportASCII(strFile);
if( !bRet )
{
out_str("Failed to import file!");
// Destroy newly created worksheet
wks.Destroy();
return;
}

// Create a default graph and plot all Y columns in the first layer
// as a grouped plot.
GraphPage gpg;
// If you wish to use a custom graph template, then specify the name
// of your template in place of Origin.OTP
gpg.Create("Origin.OTP");
// Point to the first layer in the graph
// If you use a custom template that has multiple layers, you can
// then declare separate layer objects for each layer and move
// data plots into various layers as desired
GraphLayer gly = gpg.Layers(0);
// plot the y column (column 2)
Curve crv(wks, 1);
gly.AddPlot(crv, IDM_PLOT_LINE);
// rescale
gly.Rescale();
using NLSF = LabTalk.NLSF; // Point to the NLSF object
NLSF.Init(); // Initialize the fitter
NLSF.Func$ = "gaussamp"; // Assign fitting function
NLSF.FitData$ = crv.GetName(); // Assign dataset name
NLSF.Execute("parainit"); // Perform automatic parameter initialization
NLSF.Fit(100); // Perform fit - up to 100 iterations
NLSF.PasteParams("p"); // Paste fit results to graph
}


Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 09/09/2006 08:15:58 AM

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