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
 maximum value of a worksheet
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

lillt91

Germany
14 Posts

Posted - 02/16/2018 :  05:07:26 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): OriginPro 2015G (64-bit)
Operating System:

Hi, I have a worksheet with 55 cols and 154 rows. I want the loop to run over every single column and give out the maximum value of the active worksheet. Falsely my code gives out the maximum value of the last column... Heres my script:

maxv= 848;
maxcol = 0;
maxrow = 0;

loop(ii,2,wks.ncols-1) // Loop over all columns
{

if(maxv<max(wcol(ii)))
{
maxv=max(wcol(ii));
maxcol = ii;
maxrow = limit.imax;
}
}

dlgrowcolgoto r1:=maxrow c1:=maxcol;

Edited by - lillt91 on 02/16/2018 05:20:50 AM

lillt91

Germany
14 Posts

Posted - 02/16/2018 :  08:09:38 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I found the solution:

maxv= 848;
maxcol = 0;
maxrow = 0;

loop(ii,2,wks.ncols-1) // Loop over all columns
{

limit wcol(ii);
if(maxv<max(wcol(ii)))
{
maxv = limit.ymax;
maxcol = ii;
maxrow = limit.imax;
}
}

dlgrowcolgoto r1:=$(maxrow) c1:=$(maxcol);
Go to Top of Page

Hideo Fujii

USA
1582 Posts

Posted - 02/16/2018 :  10:05:46 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi lillt91,

Just another version to avoid looping though not sure how much you get the speed gain:
//////////////////////////////////////////////
ncol=wks.ncols;
wname$=%H;     //workbook name
w2m -r 0;      //convert to matrix directly
sum(%H);       //get stats of matrix
vmax=sum.max;  //max
imax=sum.imax; //max position
maxrow=int(imax/ncol)+1; //row# in wks
maxcol=imax-ncol*int(imax/ncol); //col# in wks
window -a %(wname$); //reactivate worksheet
dlgrowcolgoto r1:=$(maxrow) c1:=$(maxcol); //highlight the cell
//////////////////////////////////////////////
--Hideo Fujii
OriginLab

Edited by - Hideo Fujii on 02/16/2018 10:08:05 AM
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