-
Notifications
You must be signed in to change notification settings - Fork 0
/
getsuper2var.c
71 lines (71 loc) · 2.14 KB
/
getsuper2var.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "mex.h"
#include "math.h"
void mexFunction(int nlhs,mxArray *plhs[],int nrhs, const mxArray *prhs[])
{
int *vector_x,*best_c,*out1;
int num_sample,avg,num1,num2,temc1;
int i,k=1,if_fix=1;
vector_x=mxGetData(prhs[0]);
avg=*((int *)mxGetData(prhs[1]));
num_sample=*((int *)mxGetData(prhs[2]));
best_c=(int *) mxCalloc(num_sample,sizeof(int));
for(i = 0;i < num_sample; i++){
best_c[i]=0;
}
for(i=1;i<num_sample;i++){
if (vector_x[i]!=vector_x[i-1]){
if (if_fix==1){
if ((i-best_c[k-1]) < avg){
num1= i-best_c[k-1];
temc1=i;
if_fix=0;
}else{
best_c[k]=i;
k=k+1;
if_fix=1;
}
}else{
num2=i-temc1;
if ((num2+num1) < avg){
num1=num2+num1;
temc1=i;
if_fix=0;
}else{
if ((avg-num1)>(num1+num2)-avg){
best_c[k]=i;
if_fix=1;
k=k+1;
}else{
best_c[k]=temc1;
k=k+1;
if (num2>=avg){
best_c[k]=i;
k=k+1;
if_fix=1;
}else{
num1=num2;
temc1=i;
if_fix=0;
}
}
}
}
}
}
if (best_c[k-1]!=num_sample){
best_c[k]=num_sample;
plhs[0]=mxCreateNumericMatrix(1,k+1,mxINT32_CLASS,mxREAL);
out1=mxGetData(plhs[0]);
for (i=0;i<k+1;i++){
out1[i]=best_c[i];
}
}else{
plhs[0]=mxCreateNumericMatrix(1,k,mxINT32_CLASS,mxREAL);
out1=mxGetData(plhs[0]);
for (i=0;i<k;i++){
out1[i]=best_c[i];
}
}
mxFree(best_c);
return;
}