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
 Problems with mod (int x, int y)

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
Jengo Posted - 06/25/2010 : 11:13:00 AM
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
9   L A T E S T    R E P L I E S    (Newest First)
Jengo Posted - 07/27/2010 : 10:17:54 AM
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!
larry_lan Posted - 07/27/2010 : 09:24:12 AM
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
Jengo Posted - 07/27/2010 : 09:13:49 AM
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;
}

larry_lan Posted - 07/26/2010 : 11:55:13 PM
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
Jengo Posted - 07/26/2010 : 07:42:46 AM
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.

Jengo Posted - 07/01/2010 : 05:43:58 AM
Thank you so much.

And I will follow your advice!

Have a great day!
larry_lan Posted - 06/30/2010 : 10:38:00 PM
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
Jengo Posted - 06/30/2010 : 08:38:50 AM
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
larry_lan Posted - 06/28/2010 : 01:32:04 AM
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

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