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
 Perform Linear Fit and Integration over worksheets

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
leonardo.a027 Posted - 05/08/2017 : 3:04:49 PM
Hi,
I am trying to perform operation on all the sheets of a specific workbook. The steps are:
1- Compute log(col(2)) of each sheet and save the values in a new column in each sheet.
2- Perform a linear fit of these new column created from row 5 to row 10 and save the result in a new column in each sheet.
3- Calculate the area of the linear fits saved in each sheet and save these values in a new workbook. Each area value should be identified by the sheet name where it comes from.

I order to to do I have tried this:


doc -e LB
{
  int j = 1;
  if (%H == "DatosMelanina")
    {
    loop(ii,1,page.nlayers)
       {
        string str = layer$(ii).name$;
        rW.addCol(LogR);
        range Reflectance = [%H]$(ii)!2;
        range logR1 = [%H]$(ii)!3;
        logR1       = -log(Reflectance);

        rW.addcol(FitData);
        fitLR iy:=(1,3) N:=(5,10) oy:=col(FitData);
        
        range Fit    = [%H]$(ii)!FitData;
        newbook MelaninIndex;
        integrate Fit;
        range Area = [MelaninIndex]Sheet1!2;
        range Name = [MelaninIndex]Sheet1!1;
        Area[j]    = integ.area/100;
        Name[j]$   = str$;
        
        j++;
      }
    }
}


But the next error shows:


layer$(ii).name$
string expression error!
STR:failed to add variable to local stack!


Also, the result I get is:
1- log(col(2)) is performed correctly
2- LinearFit is only performed in the first sheet and not the next ones.
3- Only the area of the first sheet is saved in the new workbook and not the next ones.

I don't know how to solve this.
Thanks in advance for the help.

I am using Origin Pro2016
Operating System: Windows 10
2   L A T E S T    R E P L I E S    (Newest First)
leonardo.a027 Posted - 05/09/2017 : 4:19:05 PM
Hi Amanda.
Thanks a lot for the help. I did what you suggested but the code for the linear fit doesn't select the rows from 5 to 10 to I had to add a little bit of code there. But everything else worked just fine.
Now my new code works just fine, thanks a lot.

newbook MelaninIndex;
range Area = [MelaninIndex]Sheet1!2;
range Name = [MelaninIndex]Sheet1!1;
win -a DatosMelanina;
int jj = 1;
doc -e LW
{
    string str =wks.name$;
    range Reflectance = Col(2);
    range logR        = LogR;
    logR              = -log(Reflectance);

    range linex = Col(1)[1316:1826];
    range line1 = Line1;
    line1       = linex;
    range liney = Col(3)[1316:1826];
    range line1 = Line2;
    line1       = liney;
    
    wks.col      = 4;
    wks.col.type = 4;
    
    wks.addcol(XFit);
    wks.addcol(FitData);
    fitLR iy:=(4,5) oy:=(col(XFit),col(FitData));
    

    range Fit    = FitData;
    integrate Fit;
    Area[jj]    = integ.area/100;
    Name[jj]$   = str$;

    jj++;
}
AmandaLu Posted - 05/09/2017 : 03:30:35 AM
Hi,

When workbook MelaninIndex is created, DatosMelanina is not the active workbook so STR$ cannot find the correct worksheet name. Not sure if you defined worksheet "rW". Since all worksheet you need to deal with is in workbook DatosMelaniana, I suggest you activate this workbook and then use doc -e LW to loop all worksheets in it. Please try the following:

newbook MelaninIndex;
range Area = [MelaninIndex]Sheet1!2;
range Name = [MelaninIndex]Sheet1!1;
win -a DatosMelanina;
int jj = 1;
doc -e LW
{
string str$ = wks.name$;
wks.addCol(LogR);
range Reflectance = 2;
range logR1 = 3;
logR1 = -log(Reflectance);

wks.addcol(FitData);
fitLR iy:=(1,3) N:=(5,10) oy:=col(FitData);

range Fit = FitData;

integrate Fit;
Area[jj] = integ.area/100;
Name[jj]$ = str$;

jj++;

}

Thanks,
Amanda
OriginLab Technical Service

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