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
 Perform Linear Fit and Integration over worksheets
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

leonardo.a027

Argentina
9 Posts

Posted - 05/08/2017 :  3:04:49 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
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

AmandaLu

439 Posts

Posted - 05/09/2017 :  03:30:35 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

leonardo.a027

Argentina
9 Posts

Posted - 05/09/2017 :  4:19:05 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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++;
}
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