Author |
Topic |
|
Jengo
Germany
13 Posts |
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 |
|
larry_lan
China
Posts |
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 |
Edited by - larry_lan on 06/28/2010 09:12:47 AM |
|
|
Jengo
Germany
13 Posts |
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
China
Posts |
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
Germany
13 Posts |
Posted - 07/01/2010 : 05:43:58 AM
|
Thank you so much.
And I will follow your advice!
Have a great day!
|
|
|
Jengo
Germany
13 Posts |
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.
|
|
|
larry_lan
China
Posts |
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 |
Edited by - larry_lan on 07/26/2010 11:55:29 PM |
|
|
Jengo
Germany
13 Posts |
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
China
Posts |
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
Germany
13 Posts |
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! |
|
|
|
Topic |
|