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
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum
 Origin Forum
 Fitting
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

navid.solati

7 Posts

Posted - 02/05/2018 :  02:27:14 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin):
Operating System:
Hello,
I have a script which finds the maximum point in a spectrum and put it in a matrix. Since there are more than 6000 data in each set, it opens files, reads them and after putting the result in the matrix it closes the file and goes to the next one. Now I would like to get the position (X value) of those maximum points. Could you please let me know how I can change the script so that I can reach my goal?

//Point to where the data files are

string path$ = "C:...";

findfiles ext:="*.txt"; // Find all files with wild card

int numFiles = fname.GetNumTokens(LF); // get number of files

int nFirst = 1;

//new matrixbook with 100*100 dimension

newbook mat:=1;

matrix -ps DIM 81 81;

range rr=1; //define a range for the first sheet of matrix

//loop over all files

for(int ifile = 1; ifile <= numFiles; ifile++)

{

newbook;

string filepath$;

// Get next file name

filepath$=fname.gettoken(ifile,LF)$;

// Parse out just file name without path and without extension

impasc fname:=filepath$
options.PartImp.Partial:= 1
options.PartImp.FirstRow:= 365
options.PartImp.LastRow:= 674;
filepath$=;

rr[$(ifile)]=max(col(B)); // get the maximum value for col(2) and put it to matrix cell.;

win -cd; //delete current workbook.

}

Castiel

343 Posts

Posted - 02/05/2018 :  02:52:22 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by navid.solati


rr[$(ifile)]=max(col(B)); // get the maximum value for col(2) and put it to matrix cell.;



Use sum() instead of max()
sum(col(B));
maxval = sum.max; // equivalent to max(col(B))
imaxval = sum.imax;  // index of max value



     #####
    #### _\_  ________
    ##=-[.].]| \      
    #(    _\ |  |------|
     #   __| |  ||||||||
      \  _/  |  ||||||||
   .--'--'-. |  | ____ |
  / __      `|__|[o__o]|
_(____nm_______ /____\____ 
Go to Top of Page

navid.solati

7 Posts

Posted - 02/08/2018 :  03:10:54 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you castiel,

I tried to use sum(col(b)) but it is not working and I am getting an error saying "imaxval" is an unknown function!!
Go to Top of Page

navid.solati

7 Posts

Posted - 02/08/2018 :  09:00:53 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I just realized the sum function is not what I am looking for. My data is in two columns, one is the x axis and the other is the y axis. I need to find X value for the Max Y value. As you can see in my first message, I have a code to find the Max of Y but I don't know how to find it's X value.
Go to Top of Page

Castiel

343 Posts

Posted - 02/08/2018 :  09:48:15 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by navid.solati

I just realized the sum function is not what I am looking for. My data is in two columns, one is the x axis and the other is the y axis. I need to find X value for the Max Y value. As you can see in my first message, I have a code to find the Max of Y but I don't know how to find it's X value.



https://www.originlab.com/doc/LabTalk/ref/Sum-obj


     #####
    #### _\_  ________
    ##=-[.].]| \      
    #(    _\ |  |------|
     #   __| |  ||||||||
      \  _/  |  ||||||||
   .--'--'-. |  | ____ |
  / __      `|__|[o__o]|
_(____nm_______ /____\____ 
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000