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
 Problems with mod (int x, int y)
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Jengo

Germany
13 Posts

Posted - 06/25/2010 :  11:13:00 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): V8.0988 SR6
Operating System: Win XP

Hey!
I have a problem with Origin. As you can see in the pic I added,
I wanted to use this: mod(Col(B),2*128)-128 to fix my values...
But they generate not the right values.

the original values are in column B(Y) and I need the values marked in the red scope in one column!!

I could fix the first values with mod(Col(B),2*128)-128
But for the next 12 values I needed mod(Col(B),2*-128)+128 to generate the right values.



P.S. I used this modulus in excel and it worked, but not with origin :(

Hope someone can help me!
Thanks

Jengo

larry_lan

China
Posts

Posted - 06/28/2010 :  01:32:04 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Jengo:

This is because different computer language outputs different mod() result:

In C/C++: mod(-72, 256) = -72;
Excel: mod(-72, 256) = 184;

We should not say which one is wrong, they just use different calculation and Origin follows C syntax. As a workaround, you can define a C function and call this function in LabTalk Script window or Set Column Values dialog:

int newmode(int n, int d)
{
	int c;
	c = n - d*floor((double)n/d);
	return c;
}

Thanks
Larry
OriginLab Technical Services

Edited by - larry_lan on 06/28/2010 09:12:47 AM
Go to Top of Page

Jengo

Germany
13 Posts

Posted - 06/30/2010 :  08:38:50 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I am sorry, but I am still having problem with the set column values dialog:

If I want the correct values in Column (C), which code should I use in that set column values dialog.

I am just a beginner... sorry
Go to Top of Page

larry_lan

China
Posts

Posted - 06/30/2010 :  10:38:00 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi:

Maybe you can read our programming help first to see how to create an Origin C function.

Here is a quick start for your issue:

1. Open Code Builder



2. Create a C file.



3. Type the function I provide above, and compile it.



4. Use the function in Set Column Value dialog.



Thanks
Larry
Go to Top of Page

Jengo

Germany
13 Posts

Posted - 07/01/2010 :  05:43:58 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you so much.

And I will follow your advice!

Have a great day!
Go to Top of Page

Jengo

Germany
13 Posts

Posted - 07/26/2010 :  07:42:46 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hello again:)

I want to adjust the values automatically for all columns with the function you gave me.
If someone have a idea or a link for my problem I would be glad.

Go to Top of Page

larry_lan

China
Posts

Posted - 07/26/2010 :  11:55:13 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You can use LabTalk Script to set column values within a loop. Suppose you want to set values from column 2 to the last column, run some script like:

for(int ii=2; ii<=wks.ncols; ii++)
{
	col($(ii)) = col(1) + 2;
}

Here is an example about running script in script window.

Thanks
Larry

Edited by - larry_lan on 07/26/2010 11:55:29 PM
Go to Top of Page

Jengo

Germany
13 Posts

Posted - 07/27/2010 :  09:13:49 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
should that code work in the command window as well?! or why does it not work? :(


for(ii=2;ii<wks.ncols; ii++)

{
col($(ii)) = newmode(wcol($(ii)),256)-128);
}

or

loop(ii,2,wks.ncols)

{
col($(ii)) = newmode(wcol($(ii)),256)-128);
}

as you can see above: your/my function was:

int newmode(int n, int d)
{
int c;
c = n - d*floor((double)n/d);
return c;
}

Go to Top of Page

larry_lan

China
Posts

Posted - 07/27/2010 :  09:24:12 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
for(ii=2;ii<wks.ncols; ii++)

{
col($(ii)) = newmode(wcol($(ii)),256)-128);
}

or

loop(ii,2,wks.ncols)

{
col($(ii)) = newmode(wcol($(ii)),256)-128);
}


The left and right column are the same, see the above red part.

Larry
Go to Top of Page

Jengo

Germany
13 Posts

Posted - 07/27/2010 :  10:17:54 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
aahhh I got it:

this one worked well, seems to be

loop(ii,1,wks.ncols)

{
        col($(ii)) = newmode(wcol(ii),256)-128;
}


Thank YOU!
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