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 for Programming
 Forum for Origin C
 Dataset, vector problem

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
schosch100 Posted - 07/02/2008 : 05:50:27 AM
Hi

I have a worksheet that contains 3 columns. In the first column there are my values, which switch randomly betweent 1 and 0.
Now I need a script that counts the same value (1 or 0) for one period and puts the sum in the next columns. Like:

My values /NEED count for value:1 /count for value:0
1 -------/-- 3 -------------------/--- 2
1 -------/-- 2 -------------------/--- 1
1
0
0
1
1
0
...

I tried to write a origin c program with a while loop but I was not successful :( please help

thx, schosch
2   L A T E S T    R E P L I E S    (Newest First)
schosch100 Posted - 07/07/2008 : 02:24:42 AM
it works,

thank you!!!
cjfraz Posted - 07/05/2008 : 11:48:52 PM

There might be a more parsimonious solution, but I think this code works as per your description of the problem.

Make sure that the worksheet with the input data is active and all three columns exist before you run it.

J...


void cb(){	

	//make some datasets attached to columns of active sheet as you described.
	Worksheet wks=Project.ActiveLayer();
	Dataset dsIn, ds1, ds0;	
	
	dsIn.Attach(wks,0);
	ds1.Attach(wks, 1);
	ds0.Attach(wks, 2);

	ds0.SetSize(dsIn.GetSize());
	ds1.SetSize(dsIn.GetSize());
	ds0=NANUM;
	ds1=NANUM;
	
	//declare some counters.
	int iOneCount=0;  //number of 'periods of 1s' observed.
	int iZeroCount=0; //number of 'periods of 0s' observed.
	int iSame=1;      //number of observations in current period.
	
	for (int j=1;j<dsIn.GetSize();j++){  //progress through entire input column.
		if (dsIn[j]!=dsIn[j-1]){  //if current value does not equal previous, change has occured.
		
			if (dsIn[j-1]==1){ //change was from 1 to 0 so output to 1s counter.
				ds1[iOneCount++]=iSame;
			}
			else{			   //change was from 0 to 1 so output to 0s coutner.
				ds0[iZeroCount++]=iSame;
			}			
			iSame=1;  //output of period complete, so reset streak counter.
		}
		else	iSame++;	//no change occured, so increment streak counter.	
	}
	
	//finally, take care of the last period.
	if (dsIn[j-1]==1){
		ds1[iOneCount++]=iSame; 
	}
	else{
		ds0[iZeroCount++]=iSame;
	}
	ds0.SetSize(iZeroCount);
	ds1.SetSize(iOneCount);	
	
}

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