Bonsoir,
SVP je veux exécute le code ci -joint en C sous Matlab . Merci bcp
Version imprimable
Bonsoir,
SVP je veux exécute le code ci -joint en C sous Matlab . Merci bcp
Pour commencer, il est plus respectueux de citer ses sources : Perception and Neurodynamics Laboratory (PNL) et plus précisément : http://www.cse.ohio-state.edu/~dwang...are/wang-nc97/
Le code est suffisamment simple pour être facilement transformé en MEX :
Code:
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279 /*****************************************************************/ /* This program is for 2D segmentation using the LEGION network */ /* The equations were modeled as a PDP algorithm for efficiency */ /* by DeLiang Wang in 7/94. For a detailed description of the */ /* algorithm see D.L. Wang and D. Terman: "Image segmentation */ /* based on oscillatory correlation", Neural Computation, Vol. 9 */ /* pp. 805-836, 1997 (For errata see Neural Computation 9, */ /* 1623-1626, 1997), on page 822. */ /*****************************************************************/ #include "mex.h" #include "segment.h" #define MAXVAL 32768.0 /* 2147483648.0 or 32768.0,machine (HP or SUN) dependable*/ #define MAX 32767 /* 2147483647 or 32767, machine dependable */ #define GRAY 255 /* Maximum value of a pixel */ int bi(); int jump[2], z, Num = 1; /* so we can change step size at will */ /* Num: number of the segments */ FILE *outfile, *fopen(); float x[N1][N2][2], lateral[N1][N2]; /* lateral: the sum of input from lateral connections */ float W[N1][N2][8]; /* strength of the interactions for 4 directions */ int stim[N1][N2], matrix[N1][N2]; int y[N1][N2], cycle[N1][N2], trigger[N1][N2]; /* y: integer of x; cycle: test for 1st cycle; trigger: jumping signal */ void inputs(void) { int i, j; int width, height, c; char magic[25]; float stimulus = 0.2; FILE *IN; for (i = 0; i < N1; i++) for (j = 0; j < N2; j++) matrix[i][j] = 0; IN = fopen("lake1.pgm", "r"); fscanf(IN,"%s\n%d %d\n%d\n",magic,&width,&height,&c); fprintf(stderr,"[Type %s %dx%d colours %d]\n",magic,width,height,c); for(i=0;i<160;i++) for(j=0;j<160;j++) stim[i][j] = getc(IN); fclose(IN); } void connections(void) { int i, j, k; float baseline = 0.0, Wtotal = 6.0, sum; for (i = 0; i < N1; i++) /* for eight nearest neighbors */ for (j = 0; j < N2; j++) { W[i][j][0] = W[i][j][1] = W[i][j][2] = W[i][j][3] = 0.0; W[i][j][4] = W[i][j][5] = W[i][j][6] = W[i][j][7] = 0.0; } for (i = 0; i < N1; i++) for (j = 0; j < N2; j++) { sum = 0.0; if (j-1 >= 0) W[i][j][0] = (float) GRAY/(1+abs(stim[i][j]-stim[i][j-1])); if (i-1 >= 0 && j-1 >= 0) W[i][j][1] = (float) GRAY/(1+abs(stim[i][j]-stim[i-1][j-1])); if (i-1 >= 0) W[i][j][2] = (float) GRAY/(1+abs(stim[i][j]-stim[i-1][j])); if (i-1 >= 0 && j+1 < N2) W[i][j][3] = (float) GRAY/(1+abs(stim[i][j]-stim[i-1][j+1])); if (j+1 < N2) W[i][j][4] = (float) GRAY/(1+abs(stim[i][j]-stim[i][j+1])); if (i+1 < N1 && j+1 < N2) W[i][j][5] = (float) GRAY/(1+abs(stim[i][j]-stim[i+1][j+1])); if (i+1 < N1) W[i][j][6] = (float) GRAY/(1+abs(stim[i][j]-stim[i+1][j])); if (i+1 < N1 && j-1 >= 0) W[i][j][7] = (float) GRAY/(1+abs(stim[i][j]-stim[i+1][j-1])); for (k = 0; k < 8; k++) lateral[i][j] += W[i][j][k]; } } void initiate(void) { int i,j,t, temp; /* labels for setting up display intervals */ for (i = 0; i < N1; i++) /* randomize the initial phases */ for (j = 0; j < N2; j++) { y[i][j] = rand(); x[i][j][0] = y[i][j]/(MAXVAL + 1.0); y[i][j] -= 2; if (y[i][j] < 0) y[i][j] = 0; trigger[i][j] = 0; cycle[i][j] = 0; } z = 0; /* initial display values for 2D */ for (i = 0; i < N1; i++) for (j = 0; j < N2; j++) { temp = x[i][j][0]*RP; fprintf(outfile, "%d ", temp); } } void select(void) { int i, j, max, imax=0, jmax=0; float baseline = 1200.0, temp; /* baseline 1200 -> 17 regions; 1000 -> 23 regions. Both reasonable */ max = -1; for (i = 0; i < N1; i++) for (j = 0; j < N2; j++) { trigger[i][j] = 0; if (lateral[i][j] > baseline && y[i][j] != MAX && y[i][j] > max) { max = y[i][j]; imax = i; jmax = j; } } if (cycle[imax][jmax]) { /* find out jumpers */ for (i = 0; i < N1; i++) for (j = 0; j < N2; j++) if (y[i][j] == max && cycle[i][j]) trigger[i][j] = 1; } else trigger[imax][jmax] = 1; for (i = 0; i < N1; i++) /* advance oscillators on the left branch */ for (j = 0; j < N2; j++) if (y[i][j] != MAX && (cycle[i][j] || lateral[i][j] > baseline)) { y[i][j] = y[i][j] + (MAX - max); x[i][j][0] = y[i][j]/(MAXVAL + 1.0); } } void evaluate(void) { float temp, thetae = 2.0, temp2, temp3; int i,j,t, cat, count; /* labels for setting up display intervals */ jump[0] = 0; select(); for ( t = 0; t < WIDTH-1; t++) { count = 0; for (i = 0; i < N1; i++) for (j = 0; j < N2; j++) { /* compute net input */ if (x[i][j][0] > thetae && jump[0] == 0) { /* jumping down */ x[i][j][1] = LP; y[i][j] = -1; cycle[i][j] = 1; count++; } else if (x[i][j][0] < thetae) { /* summing up overall input */ temp = -20.0 * bi((float) z,0.5); /* used to be 50 */ /* the following is based on traversing through strongest link */ temp2 = 0.0; if (j-1 >= 0) { temp3 = W[i][j][0] * bi(x[i][j-1][0], thetae); if (temp2 < temp3) temp2 = temp3; } if (i-1 >= 0 && j-1 >= 0) { temp3 = W[i][j][1] * bi(x[i-1][j-1][0], thetae); if (temp2 < temp3) temp2 = temp3; } if (i-1 >= 0) { temp3 = W[i][j][2] * bi(x[i-1][j][0], thetae); if (temp2 < temp3) temp2 = temp3; } if (i-1 >= 0 && j+1 < N2) { temp3 = W[i][j][3] * bi(x[i-1][j+1][0], thetae); if (temp2 < temp3) temp2 = temp3; } if (j+1 < N2) { temp3 = W[i][j][4] * bi(x[i][j+1][0], thetae); if (temp2 < temp3) temp2 = temp3; } if (i+1 < N1 && j+1 < N2) { temp3 = W[i][j][5] * bi(x[i+1][j+1][0], thetae); if (temp2 < temp3) temp2 = temp3; } if (i+1 < N1) { temp3 = W[i][j][6] * bi(x[i+1][j][0], thetae); if (temp2 < temp3) temp2 = temp3; } if (i+1 < N1 && j-1 >= 0) { temp3 = W[i][j][7] * bi(x[i+1][j-1][0], thetae); if (temp2 < temp3) temp2 = temp3; } temp += temp2; if (trigger[i][j] || temp > 0.25) { /* jumping up */ x[i][j][1] = RP; y[i][j] = MAX; jump[1] = 1; z++; } else x[i][j][1] = x[i][j][0]; } else x[i][j][1] = x[i][j][0]; } z -= count; if (jump[1] == 0 && z == 0) select(); /* store for display in 2d case*/ if (jump[1] == 0 && jump[0] == 1) { mexPrintf("we are here \n"); Num++; for (i = 0; i < N1; i++) for (j = 0; j < N2; j++) { if (z > 0) { if (x[i][j][1] < thetae) cat = 0; else cat = x[i][j][1]; } else cat = x[i][j][1]; fprintf(outfile, "%d ", cat); if (Num < 25 && cat > 0) matrix[N1-1-i][j] = 26-Num; /* 17 regions, or 23 */ } } for (i = 0; i < N1; i++) for (j = 0; j < N2; j++) /* replace OLD by NEW */ x[i][j][0] = x[i][j][1]; jump[0] = jump[1]; jump[1] = 0; } } void store(void) { int i, j; FILE *out, *out1, *fopen(); mexPrintf("The number of the segments/cycles is %d\n", Num); out = fopen("NUMBER", "w"); out1 = fopen("Result", "w"); fprintf(out, "%d ", Num); for (i = 0; i < N1; i++) for (j = 0; j < N2; j++) fprintf(out1, "%d ", matrix[i][j]); fclose(out); fclose(out1); } void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { int *pr_seed; pr_seed = (int *)mxGetData(prhs[0]); srand(*pr_seed); outfile = fopen("Out", "w"); inputs(); connections(); initiate(); evaluate(); store(); fclose(outfile); } int bi(x, threshold) float x, threshold; { if (x > threshold) return (1); else return (0); }
A compiler comme ceci :
Et à utiliser comme ceci :Code:mex segment.c
Code:
1
2 seed = int32(5); segment(seed);
Merci Mr.Jérôme Briot pour votre aide , mais je vous demande plus de détailles car je suis débutant en programmation ,
est ce que je dois convertie le code .txt en code .c puis en MEX ??? Merci d’avance
Comme mentionné dans la FAQ, il te faut tout d'abord un compilateur pour compiler le fichier MEX.
Quelle version de MATLAB utilises-tu ? Avec quel système d'exploitation ? 32 ou 64 bits ?
Voir la FAQ Quels sont les différents compilateurs supportés pour compiler un fichier MEX ? pour choisir un compilateur.
MATLAB 7.10.0 (R2010a) , windows 7 ,32 bits
OK, donc tu suis les instructions données ici Comment choisir le compilateur à utiliser pour créer un fichier MEX ? et tu choisis le compilateur Lcc dans la liste proposée.
J'ai essai , matlab m'affiche ce message :Code:
1
2
3
4 Please verify your choices: Compiler: Lcc-win32 C 2.4.1 Location: C:\PROGRA~1\MATLAB\R2010a\sys\lcc
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 Are these correct [y]/n? y Trying to update options file: C:\Users\zied\AppData\Roaming\MathWorks\MATLAB\R2010a\mexopts.bat From template: C:\PROGRA~1\MATLAB\R2010a\bin\win32\mexopts\lccopts.bat Done . . . ************************************************************************** Warning: The MATLAB C and Fortran API has changed to support MATLAB variables with more than 2^32-1 elements. In the near future you will be required to update your code to utilize the new API. You can find more information about this at: http://www.mathworks.com/support/sol...ution=1-5C27B9 Building with the -largeArrayDims option enables the new API. **************************************************************************
Donc maintenant tu enregistres le code C que j'ai fourni précédemment dans un fichier segment.c
Tu copies le fichier segment.h dans le même dossier que segment.c puis tu fais :
Code:mex segment.c
j'ai copier les deux fichier segment .c + segment.h a "C:\PROGRA~1\MATLAB\R2010A\BIN\"
j'ai executé la commande mex segment.c
Matlab affiche ce message
C:\PROGRA~1\MATLAB\R2010A\BIN\MEX.PL: Error: 'segment.c' not found.
??? Error using ==> mex at 222
Unable to complete successfully.
:''(
Premièrement, il ne faut pas utiliser le fichier segment.c que tu as téléchargé sur le site du "Perception and Neurodynamics Laboratory" mais celui que j'ai modifié dans ce message . As-tu au moins remarqué les quelques différences entre les deux codes… j'en doute.
Deuxièmement, il ne faut pas copier les fichiers dans le dossier d'installation de MATLAB.
Place les, par exemple, dans le dossier dans lequel MATLAB démarre.
Pour finir, il faut absolument que le dossier où se trouvent ces deux fichiers soit le dossier courant de MATLAB avant de les compiler avec mex
Bonjour , normalement c'est bon , matlab m’affiche le message suivant
Mais la question qui ce pose comment modifier l'Input de segment.c avec mon Input ??????? !!!!!Code:
1
2
3
4
5
6
7 >> mex segment.c seed = int32(5); segment(seed); we are here ....... we are here The number of the segments/cycles is 348
en attendant monsieur votre réponse veuillez agréer mes salutations les meilleures.
oui exactement c'est ca
Voici une version :
Code:
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298 /*****************************************************************/ /* This program is for 2D segmentation using the LEGION network */ /* The equations were modeled as a PDP algorithm for efficiency */ /* by DeLiang Wang in 7/94. For a detailed description of the */ /* algorithm see D.L. Wang and D. Terman: "Image segmentation */ /* based on oscillatory correlation", Neural Computation, Vol. 9 */ /* pp. 805-836, 1997 (For errata see Neural Computation 9, */ /* 1623-1626, 1997), on page 822. */ /*****************************************************************/ #include "mex.h" #include "segment.h" #define MAXVAL 32768.0 /* 2147483648.0 or 32768.0,machine (HP or SUN) dependable*/ #define MAX 32767 /* 2147483647 or 32767, machine dependable */ #define GRAY 255 /* Maximum value of a pixel */ int bi(); int jump[2], z, Num = 1; /* so we can change step size at will */ /* Num: number of the segments */ FILE *outfile, *fopen(); float x[N1][N2][2], lateral[N1][N2]; /* lateral: the sum of input from lateral connections */ float W[N1][N2][8]; /* strength of the interactions for 4 directions */ int stim[N1][N2], matrix[N1][N2]; int y[N1][N2], cycle[N1][N2], trigger[N1][N2]; /* y: integer of x; cycle: test for 1st cycle; trigger: jumping signal */ int inputs(char *filename) { int i, j; int width, height, c; char magic[25]; float stimulus = 0.2; FILE *IN; for (i = 0; i < N1; i++) for (j = 0; j < N2; j++) matrix[i][j] = 0; IN = fopen(filename, "r"); if(IN==NULL) return -1; fscanf(IN,"%s\n%d %d\n%d\n",magic,&width,&height,&c); fprintf(stderr,"[Type %s %dx%d colours %d]\n",magic,width,height,c); for(i=0;i<160;i++) for(j=0;j<160;j++) stim[i][j] = getc(IN); fclose(IN); return 0; } void connections(void) { int i, j, k; float baseline = 0.0, Wtotal = 6.0, sum; for (i = 0; i < N1; i++) /* for eight nearest neighbors */ for (j = 0; j < N2; j++) { W[i][j][0] = W[i][j][1] = W[i][j][2] = W[i][j][3] = 0.0; W[i][j][4] = W[i][j][5] = W[i][j][6] = W[i][j][7] = 0.0; } for (i = 0; i < N1; i++) for (j = 0; j < N2; j++) { sum = 0.0; if (j-1 >= 0) W[i][j][0] = (float) GRAY/(1+abs(stim[i][j]-stim[i][j-1])); if (i-1 >= 0 && j-1 >= 0) W[i][j][1] = (float) GRAY/(1+abs(stim[i][j]-stim[i-1][j-1])); if (i-1 >= 0) W[i][j][2] = (float) GRAY/(1+abs(stim[i][j]-stim[i-1][j])); if (i-1 >= 0 && j+1 < N2) W[i][j][3] = (float) GRAY/(1+abs(stim[i][j]-stim[i-1][j+1])); if (j+1 < N2) W[i][j][4] = (float) GRAY/(1+abs(stim[i][j]-stim[i][j+1])); if (i+1 < N1 && j+1 < N2) W[i][j][5] = (float) GRAY/(1+abs(stim[i][j]-stim[i+1][j+1])); if (i+1 < N1) W[i][j][6] = (float) GRAY/(1+abs(stim[i][j]-stim[i+1][j])); if (i+1 < N1 && j-1 >= 0) W[i][j][7] = (float) GRAY/(1+abs(stim[i][j]-stim[i+1][j-1])); for (k = 0; k < 8; k++) lateral[i][j] += W[i][j][k]; } } void initiate(void) { int i,j,t, temp; /* labels for setting up display intervals */ for (i = 0; i < N1; i++) /* randomize the initial phases */ for (j = 0; j < N2; j++) { y[i][j] = rand(); x[i][j][0] = y[i][j]/(MAXVAL + 1.0); y[i][j] -= 2; if (y[i][j] < 0) y[i][j] = 0; trigger[i][j] = 0; cycle[i][j] = 0; } z = 0; /* initial display values for 2D */ for (i = 0; i < N1; i++) for (j = 0; j < N2; j++) { temp = x[i][j][0]*RP; fprintf(outfile, "%d ", temp); } } void select(void) { int i, j, max, imax=0, jmax=0; float baseline = 1200.0, temp; /* baseline 1200 -> 17 regions; 1000 -> 23 regions. Both reasonable */ max = -1; for (i = 0; i < N1; i++) for (j = 0; j < N2; j++) { trigger[i][j] = 0; if (lateral[i][j] > baseline && y[i][j] != MAX && y[i][j] > max) { max = y[i][j]; imax = i; jmax = j; } } if (cycle[imax][jmax]) { /* find out jumpers */ for (i = 0; i < N1; i++) for (j = 0; j < N2; j++) if (y[i][j] == max && cycle[i][j]) trigger[i][j] = 1; } else trigger[imax][jmax] = 1; for (i = 0; i < N1; i++) /* advance oscillators on the left branch */ for (j = 0; j < N2; j++) if (y[i][j] != MAX && (cycle[i][j] || lateral[i][j] > baseline)) { y[i][j] = y[i][j] + (MAX - max); x[i][j][0] = y[i][j]/(MAXVAL + 1.0); } } void evaluate(void) { float temp, thetae = 2.0, temp2, temp3; int i,j,t, cat, count; /* labels for setting up display intervals */ jump[0] = 0; select(); for ( t = 0; t < WIDTH-1; t++) { count = 0; for (i = 0; i < N1; i++) for (j = 0; j < N2; j++) { /* compute net input */ if (x[i][j][0] > thetae && jump[0] == 0) { /* jumping down */ x[i][j][1] = LP; y[i][j] = -1; cycle[i][j] = 1; count++; } else if (x[i][j][0] < thetae) { /* summing up overall input */ temp = -20.0 * bi((float) z,0.5); /* used to be 50 */ /* the following is based on traversing through strongest link */ temp2 = 0.0; if (j-1 >= 0) { temp3 = W[i][j][0] * bi(x[i][j-1][0], thetae); if (temp2 < temp3) temp2 = temp3; } if (i-1 >= 0 && j-1 >= 0) { temp3 = W[i][j][1] * bi(x[i-1][j-1][0], thetae); if (temp2 < temp3) temp2 = temp3; } if (i-1 >= 0) { temp3 = W[i][j][2] * bi(x[i-1][j][0], thetae); if (temp2 < temp3) temp2 = temp3; } if (i-1 >= 0 && j+1 < N2) { temp3 = W[i][j][3] * bi(x[i-1][j+1][0], thetae); if (temp2 < temp3) temp2 = temp3; } if (j+1 < N2) { temp3 = W[i][j][4] * bi(x[i][j+1][0], thetae); if (temp2 < temp3) temp2 = temp3; } if (i+1 < N1 && j+1 < N2) { temp3 = W[i][j][5] * bi(x[i+1][j+1][0], thetae); if (temp2 < temp3) temp2 = temp3; } if (i+1 < N1) { temp3 = W[i][j][6] * bi(x[i+1][j][0], thetae); if (temp2 < temp3) temp2 = temp3; } if (i+1 < N1 && j-1 >= 0) { temp3 = W[i][j][7] * bi(x[i+1][j-1][0], thetae); if (temp2 < temp3) temp2 = temp3; } temp += temp2; if (trigger[i][j] || temp > 0.25) { /* jumping up */ x[i][j][1] = RP; y[i][j] = MAX; jump[1] = 1; z++; } else x[i][j][1] = x[i][j][0]; } else x[i][j][1] = x[i][j][0]; } z -= count; if (jump[1] == 0 && z == 0) select(); /* store for display in 2d case*/ if (jump[1] == 0 && jump[0] == 1) { mexPrintf("we are here \n"); Num++; for (i = 0; i < N1; i++) for (j = 0; j < N2; j++) { if (z > 0) { if (x[i][j][1] < thetae) cat = 0; else cat = x[i][j][1]; } else cat = x[i][j][1]; fprintf(outfile, "%d ", cat); if (Num < 25 && cat > 0) matrix[N1-1-i][j] = 26-Num; /* 17 regions, or 23 */ } } for (i = 0; i < N1; i++) for (j = 0; j < N2; j++) /* replace OLD by NEW */ x[i][j][0] = x[i][j][1]; jump[0] = jump[1]; jump[1] = 0; } } void store(void) { int i, j; FILE *out, *out1, *fopen(); mexPrintf("The number of the segments/cycles is %d\n", Num); out = fopen("NUMBER", "w"); out1 = fopen("Result", "w"); fprintf(out, "%d ", Num); for (i = 0; i < N1; i++) for (j = 0; j < N2; j++) fprintf(out1, "%d ", matrix[i][j]); fclose(out); fclose(out1); } void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { int *pr_seed, status; mwSize buflen; char *buf; pr_seed = (int *)mxGetData(prhs[0]); buflen = mxGetM(prhs[1])*mxGetN(prhs[1]); buf = mxCalloc(buflen, sizeof(char)); mxGetString(prhs[1], buf, buflen+1); srand(*pr_seed); status = inputs(buf); if(status) { mxFree(buf); mexErrMsgTxt("Pb with file"); } outfile = fopen("Out", "w"); connections(); initiate(); evaluate(); store(); fclose(outfile); mxFree(buf); } int bi(x, threshold) float x, threshold; { if (x > threshold) return (1); else return (0); }
A utiliser comme ceci :
Code:
1
2 seed = int32(5); segment(seed,'lake1.pgm');
mon entrée dans la fonction segmentation est une image de "Canal de corrélation croisée" d'un signal mixer, le Canal corrélation croisée est définie dans matlab par cette fonction :
jai tapé la code suivantCode:cross = crossChanCorr(c)
j'ai obtenu le message suivant :Code:
1
2
3 mex segment.c seed = int32(5); segment(seed,cross);
je sais pas est ce que juste ou nn !!!!!!Code:
1
2 we are here The number of the segments/cycles is 695
vous trouvez ci joint limage de "Canal de corrélation croisée" avec le système.
La ligne suivante n'a pas besoin d'être répétée à chaque fois :
Sauf si tu modifies le contenu du fichier segment.cCode:mex segment.c
Pour le reste, tout ce que je peux dire c'est que le code génère trois fichiers : Out, NUMBER et Result
Bonjour M. Jérôme Briot , j'ai téléchargé le code de groupe.c et groupe.h par le lien : http://www.cse.ohio-state.edu/pnl/sh...tnn99/dynamic/
J'ai essayé de le exécuté sur matlab par la code :
matlab affiche l'erreur suivanteCode:mex group.c
Code:
1
2
3
4
5
6
7
8
9
10 mex group.c c:\users\zied\appdata\local\temp\mex_kf~1\group.obj: multiple definition of _main first definition is in file c:\progra~1\matlab\r2010a\sys\lcc\lib\libcrt0.obj Specified export _mexFunction is not defined Missing exports. Aborting C:\PROGRA~1\MATLAB\R2010A\BIN\MEX.PL: Error: Link of 'group.mexw32' failed. ??? Error using ==> mex at 222 Unable to complete successfully.
Différences sûrement toujours pas remarquées...
Il serait temps de lire minutieusement le contenu de ce lien afin de bien comprendre la logique des fichiers MEX qui ne passent pas par une fonction d'entrée main() mais mexFunction() !
bonjour , j'ai pas trouvé la bonne explication dans ce lien http://matlab.developpez.com/faq/?page=mex
Ouvre les deux fichiers segment.c (l'original et celui que j'ai modifié) côte à côte dans un éditeur de texte.
Compare les lignes par lignes pour bien identifier les différences, dont la plus notable est, comme l'a fait remarqué Winjerome, l'absence de main dans le MEX
Bonjour , J'ai modifier le code mais matlab m'affiche des erreur !!!!
le code group.c modifier
l'erreur Matlab:Code:
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687 /*****************************************************************/ /* This program is for grouping in speech segregation using */ /* Terman-Wang oscillators. These equations are solved */ /* in the sigular limit (Linsay-Wang), and the potential is */ /* included here. Real signals. by DeLiang Wang, 8/97 */ /*****************************************************************/ #include "mex.h" #include "group.h" #define MAXVAL 32768.0 /* 2147483648.0 or 32768.0,machine (HP or SUN) dependable*/ #define MAX 32767 /* 2147483647 or 32767, machine dependable */ float Gamma = 6.5; /* CAREFUL: this value offset Wz = 1.5 */ float alpha = 5.0; float theta = -0.5; float lambda = 0.1; /* rate of developing potential */ float time = 0.0; /* global time */ float rnd(), getx(), getxx(), lateral(); int Hp[N1][N2]; /* argument to the Heaviside for potential */ int Num = 0, longseg; /* number of major phase updates */ float y[N1][N2],cubic[N1][N2],p[N1][N2],show[M][STEPS]; float shows[Ms][STEPS], showp[Mp][STEPS]; float W[N1][N2][N1]; /* strength of the interactions */ float input[N1][N2]; /* overall input an oscillator receives */ float We = 0.5, Wi = -0.5; /* We: total excit weight; C: count */ int branch[N1][N2], ext[N1][N2], ext2[N1][N2], segment[SEG][2]; int speech[N1][N2], phone[N1][N2]; /* for storing and display */ int chance[SEG], jumpup[SEG]; /* branch: keeps track of whether an oscillator is on LB or RB */ /* ext2: segment information */ void inputs(void) { FILE *fopen(), *finput, *fout; int i, j, k, l, maxy, temp, temp1, temp2, label[N1]; int width, height, c; char magic[25]; float stim = 0.2; for (i = 0; i < N1; i++) for (j = 0; j < N2; j++) input[i][j] = -10.0; finput = fopen("v8n6.pitchmask.pgm", "r"); fscanf(finput,"%s\n%d %d\n%d\n",magic,&width,&height,&c); for(j=0;j<N2;j++) for(i=0;i<N1;i++) fscanf(finput, "%d",&ext[i][j]); finput = fopen("v8n6-seg.pgm", "r"); fscanf(finput,"%s\n%d %d\n%d\n",magic,&width,&height,&c); for(i=0;i<N1;i++) for(j=0;j<N2;j++) fscanf(finput, "%d",&ext2[N1-1-i][j]); /* for storing and display purposes */ finput = fopen("Snap1", "r"); for(i=0;i<N1;i++) for(j=0;j<N2;j++) fscanf(finput, "%d",&speech[i][j]); finput = fopen("Snap2", "r"); for(i=0;i<N1;i++) for(j=0;j<N2;j++) fscanf(finput, "%d",&phone[i][j]); /* masking by segments */ for(i=0;i<N1;i++) for(j=0;j<N2;j++) if (ext2[i][j] == 0) ext[i][j] = 0; /* fout = fopen("phone1", "w"); for(i=0;i<N1;i++) for(j=0;j<N2;j++) fprintf(fout, "%d ",ext[i][j]); fclose(fout); fout = fopen("phone2", "w"); for(i=0;i<N1;i++) for(j=0;j<N2;j++) fprintf(fout, "%d ",ext2[i][j]); fclose(fout); */ /* identify longest segment and clip accordingly */ for (i = 0; i < SEG; i++) { segment[i][0] = N2; segment[i][1] = 0; } for (i = 0; i < N1; i++) for (j = 0; j < N2; j++) { temp = ext2[i][j]; if (segment[temp][0] > j) segment[temp][0] = j; if (segment[temp][1] < j) segment[temp][1] = j; } maxy = 0; for (i = 1; i < SEG; i++) /* excluding the background */ if (segment[i][1] - segment[i][0] + 1 > maxy) { maxy = segment[i][1] - segment[i][0] + 1; longseg = i; } mexprintf("longest segment is %d, and has columns %d\n", longseg, maxy); for (j = 0; j < segment[longseg][0]; j++) for (i = 0; i < N1; i++) ext[i][j] = 0; for (j = segment[longseg][1] + 1; j < N2; j++) for (i = 0; i < N1; i++) ext[i][j] = 0; /* recompute segment lengths */ k = segment[longseg][0]; l = segment[longseg][1]; for (i = 0; i < SEG; i++) { segment[i][0] = N2; segment[i][1] = 0; } for (i = 0; i < N1; i++) for (j = k; j <= l; j++) { temp = ext2[i][j]; if (segment[temp][0] > j) segment[temp][0] = j; if (segment[temp][1] < j) segment[temp][1] = j; } for (i = 1; i < SEG; i++) if (segment[i][1] - segment[i][0] < 2) { /* threshold out <3-frame seg */ for(k=0;k<N1;k++) /* caused by clipping */ for(l=0;l<N2;l++) if (ext2[k][l] == i) ext[k][l] = 0; } for(i=0;i<N1;i++) for(j=0;j<N2;j++) if (ext[i][j] > 0) input[i][j] = stim; /* smoothen within each column of each segment */ for (j = segment[longseg][0]; j <= segment[longseg][1]; j++) { for (i = 0; i < N1; i++) label[i] = 0; for (i = 0; i < N1; i++) if (label[i] == 0 && ext[i][j] > 0) { temp = ext2[i][j]; temp1 = temp2 = 0; for (k = 0; k < N1; k++) if (ext2[k][j] == temp) { if (ext[k][j] == 1) temp1++; else if (ext[k][j] == 2) temp2++; } for (k = 0; k < N1; k++) if (ext2[k][j] == temp && ext[k][j] > 0) { label[k] = 1; if (temp1 > temp2) ext[k][j] = 1; else ext[k][j] = 2; } } } fout = fopen("phone3", "w"); for(i=0;i<N1;i++) for(j=0;j<N2;j++) fprintf(fout, "%d ",ext[i][j]); fclose(fout); /* high "potential" */ input[8][N2/2] = 0.21; /* 20 for v3n6; 8 for v8n6 */ mexprintf("The segment number with high potential is %d\n", ext2[8][N2/2]); } void connections(void) { int i, j, k; /* e: excitatory; i: inhibitory; l: lateral */ for (i = 0; i < N1; i++) { for (j = segment[longseg][0]; j <= segment[longseg][1]; j++) { for (k = 0; k < N1; k++) /* initialize connections */ W[i][j][k] = 0.0; if (ext[i][j] == 1) { for (k = 0; k < N1; k++) if (k != i && ext2[k][j] != ext2[i][j] ) { if (ext[k][j] == 1) W[i][j][k] = We; else if (ext[k][j] == 2) W[i][j][k] = Wi; } } else if (ext[i][j] == 2) for (k = 0; k < N1; k++) if (k != i && ext2[k][j] != ext2[i][j] ) { if (ext[k][j] == 2) W[i][j][k] = We; else if (ext[k][j] == 1) W[i][j][k] = Wi; } } } mexprintf("weights are \n"); mexprintf("weights are \n"); mexprintf("W[0][0] are %f %f\n", W[0][0][1], W[0][0][2]); mexprintf("W[1][4] are %f %f\n", W[1][4][0], W[1][4][2]); mexprintf("W[2][6] are %f %f\n", W[2][6][0], W[2][6][1]); mexprintf("\n"); } void initiate(void) { int i,j,seed,counts,countp; /* labels for setting up display intervals */ float angle, temp; mexprintf("Input a seed now\n"); /* 2342 for potential; 111 no potent.*/ scanf("%d",&seed); srand(seed); /* randomize the initial phases */ temp = 2.0*Gamma*rnd(); for (i = 0; i < N1; i++) for (j = 0; j < N2; j++) { /* Initial phases */ if (ext[i][j] > 0) y[i][j] = temp + input[i][j]; else y[i][j] = 2.0*Gamma*rnd(); branch[i][j] = 0; /* p[i][j] = 0.0; Hp[i][j] = 0; */ cubic[i][j] = input[i][j]; } for (i = 0; i < SEG; i++) { chance[i] = 1; jumpup[i] = 0; } /* initial display values for 1D */ for (i = 0; i < N1; i = i+2) show[i/2][0] = getxx(y[i][COL]-cubic[i][COL], 0); /* initial display values for two storage arrays */ counts = countp = 0; /* for collecting display data for two streams */ for (i = 0; i < N1; i++) for (j = 0; j < N2; j++) { if (speech[i][j] && (counts%20 == 0)) shows[counts/20][0] = getxx(y[i][j]-cubic[i][j],0); else if (phone[i][j] && (countp%20 == 0)) showp[countp/20][0] = getxx(y[i][j]-cubic[i][j],0); if (speech[i][j]) counts++; else if (phone[i][j]) countp++; } /* initial display values for 2D */ /* for (i = 0; i < N1; i++) for (j = 0; j < N2; j++) show[N2*i+j][0] = getxx(y[i][j]-cubic[i][j], 0); */ } findtmin(tmin, mu, ilead, jlead) float *tmin, *mu; int *ilead, *jlead; /* Find shortest time-to-knee when no oscillator is ready to jump */ { int i, j, il, jl, ir, jr; float temp, minl = MAXVAL, minr = MAXVAL, yknee; for (i = 0; i < N1; i++) for (j = segment[longseg][0]; j <= segment[longseg][1]; j++) { if (branch[i][j]) { /* on RB */ yknee = (y[i][j]-2.0*Gamma)/(cubic[i][j]+4.0-2.0*Gamma); if (yknee < minr && yknee > 0.0) /* exclude stable fixed point */ {minr = yknee; ir = i; jr = j;} } else { /* on LB */ yknee = y[i][j]/cubic[i][j]; if (yknee < minl && yknee > 0.0) /* exclude stable fixed point */ {minl = yknee; il = i; jl = j;} } } if (minl < 1.0) {*tmin = 0.0; *mu = 1.0; *ilead = il; *jlead = jl;} else if (minr < 1.0) {*tmin = 0.0; *mu = 1.0; *ilead = ir; *jlead = jr;} else { *tmin = log(minl); *mu = minl; *ilead = il; *jlead = jl; temp = log(minr); if (temp < *tmin) { *tmin = temp; *mu = minr; *ilead = ir; *jlead = jr; } } } void jump(void) /* activity at the jump (up or down) time */ { int i, j, k, l, count, jumped = 1, Tij = 2, flag = 1, cat[N1][N2]; /* Tij: permanent weight */ int temp, curseg; float We1 = 4.0, We2 = 0.1; while (jumped) { jumped = 0; for (i = 0; i < N1; i++) for (j = 0; j < N2; j++) cat[i][j] = 0; for (i = 0; i < N1; i++) for (j = segment[longseg][0]; j <= segment[longseg][1]; j++) if (ext[i][j] > 0 && ext2[i][j] > 0) { /* compute net input */ if (p[i][j] > theta) /* thrshld for exp(-alpha*t) */ cubic[i][j] = input[i][j]; else cubic[i][j] = baseline; /* update cubics within each segment */ count = 0; curseg = ext2[i][j]; for (k = segment[curseg][0]; k <= segment[curseg][1]; k++) { temp = 0; for (l = 0; l < N1; l++) if (ext2[l][k] == ext2[i][j] && branch[l][k]) temp = 1; if (temp == 1) count++; } temp = ext2[i][j]; if (ext[i][j]>0 && count>(1+segment[temp][1]-segment[temp][0])/2) /* strict majarity rule: >; less >= (1+.) */ cubic[i][j] += We1; else if (ext[i][j] > 0 && segment[temp][1] == segment[temp][0]+count*2-1) { /* break symmetry */ if (chance[curseg]) cubic[i][j] += We2; else cubic[i][j] += We1; } else if (ext[i][j] > 0 && count > 0) cubic[i][j] += We2; /* update cubics within each column */ if (branch[i][j] == 0) cubic[i][j] += lateral(i,j); if (!branch[i][j] && y[i][j]<cubic[i][j]+error) { /* jump up */ cat[i][j] = 1; jumped = 1; cubic[i][j] -= lateral(i,j); jumpup[curseg] = 1; } else if (branch[i][j] && y[i][j]>cubic[i][j]+4.0-error) { /* jump down */ cat[i][j] = -1; jumped = 1; cubic[i][j] += lateral(i,j); } } for (i = 0; i < N1; i++) for (j = 0; j < N2; j++) { /* update jumps */ if (cat[i][j] > 0) branch[i][j] = 1; else if (cat[i][j] < 0) branch[i][j] = 0; } } for (i = 1; i < SEG; i++) if (jumpup[i]) { temp = 0; for (k = segment[i][0]; k <= segment[i][1]; k++) for (l = 0; l < N1; l++) if (ext2[l][k] == i && branch[l][k]) temp = 1; if (temp == 0) { chance[i] = 1 - chance[i]; jumpup[i] = 0; } } /* compute Hp[i][j] */ /* for (i = 0; i < N1; i++) for (j = 0; j < N2; j++) { Hp[i][j] = 0; if (i-1 >= 0 && branch[i-1][j]) Hp[i][j] += Tij; if (i+1 < N1 && branch[i+1][j]) Hp[i][j] += Tij; if (j-1 >= 0 && branch[i][j-1]) Hp[i][j] += Tij; if (j+1 < N2 && branch[i][j+1]) Hp[i][j] += Tij; if (Hp[i][j] > 7) Hp[i][j] = 1; else Hp[i][j] = 0; } */ } void evaluate(void) { float intv, mu, current, length, xval, yval, angle, temp, cat; int ilead, jlead, num; /* leading oscillator, and no of jumpers */ int counts, countp; /* counts for speech and phone respectively */ int i,j,step,bef,aft; /* labels for setting up display intervals */ FILE *outf, *fopen(); outf = fopen("Out", "w"); bef = 0; length = delta*(STEPS-1); /* reduce one step to facilitate display */ while (time < length) { findtmin(&intv, &mu, &ilead, &jlead); aft = (time+intv)/delta; /* store for display in 1d case*/ for (step = bef; step < aft && step < STEPS-1; step++) { for (i = 0; i < N1; i = i+2) { temp = -((1.0+step)*delta - time); if (branch[i][COL]) yval = (y[i][COL] - 2*Gamma)*exp(temp) + 2*Gamma - cubic[i][COL]; else yval = y[i][COL]*exp(temp) - cubic[i][COL]; show[i/2][step+1] = getxx(yval,branch[i][COL]); } counts = countp = 0; /* for collecting display data for two streams */ for (i = 0; i < N1; i++) for (j = 0; j < N2; j++) { if (speech[i][j] && (counts%20 == 0)) { temp = -((1.0+step)*delta - time); if (branch[i][j]) yval = (y[i][j] - 2*Gamma)*exp(temp) + 2*Gamma - cubic[i][j]; else yval = y[i][j]*exp(temp) - cubic[i][j]; shows[counts/20][step+1] = getxx(yval,branch[i][j]); } else if (phone[i][j] && (countp%20 == 0)) { temp = -((1.0+step)*delta - time); if (branch[i][j]) yval = (y[i][j] - 2*Gamma)*exp(temp) + 2*Gamma - cubic[i][j]; else yval = y[i][j]*exp(temp) - cubic[i][j]; showp[countp/20][step+1] = getxx(yval,branch[i][j]); } if (speech[i][j]) counts++; else if (phone[i][j]) countp++; } } /* store for display in 2d case*/ /* for (step = bef; step < aft && step < STEPS-1; step++) { for (i = 0; i < N1; i++) for (j = 0; j < N2; j++) { temp = -((1.0+step)*delta - time); if (branch[i][j]) yval = (y[i][j] - 2*Gamma)*exp(temp) + 2*Gamma - cubic[i][j]; else yval = y[i][j]*exp(temp) - cubic[i][j]; show[N2*i+j][step+1] = getxx(yval,branch[i][j]); } } */ for (i = 0; i < N1; i++) /* advance oscillators */ for (j = 0; j < N2; j++) { if (branch[i][j]) y[i][j] = (y[i][j]-2.0*Gamma)/mu + 2.0*Gamma; else y[i][j] = y[i][j]/mu; } /* update oscillator potential */ /* for (i = 0; i < N1; i++) for (j = 0; j < N2; j++) if (Hp[i][j] && input[i][j] > 0.0) p[i][j] = 1.0-(1.0-p[i][j])/mu; */ if (branch[ilead][jlead]) { branch[ilead][jlead] = 0; /* priming(jlead);*/ cubic[ilead][jlead] += lateral(ilead,jlead); } else { branch[ilead][jlead] = 1; /* priming(jlead);*/ cubic[ilead][jlead] -= lateral(ilead,jlead); } jump(); /* fast time activity */ Num++; mexprintf("Num = %d, time = %f, intv = %f\n", Num, time, intv); for(i=0;i<N1;i++) for(j=0;j<N2;j++) fprintf(outf, "%d ",branch[i][j]); time += intv; bef = aft; } fclose(outf); } void store(void) { int i,j,t,count; float max_v = 0.0, min_v = 0.0; FILE *outfile,*out,*fopen(); outfile = fopen("Output", "w"); out = fopen("NUMBER", "w"); fprintf(out, "%d ", Num); mexprintf("The number of the segments/cycles is %d\n", Num); /* for (i = 0; i < M; i++) for (t = 0; t < STEPS; t++) { if (show[i][t] > max_v) max_v = show[i][t]; if (show[i][t] < min_v) min_v = show[i][t]; } */ for (i = 0; i < Ms; i++) for (t = 0; t < STEPS; t++) { if (shows[i][t] > max_v) max_v = shows[i][t]; if (shows[i][t] < min_v) min_v = shows[i][t]; } for (i = 0; i < Mp; i++) for (t = 0; t < STEPS; t++) { if (showp[i][t] > max_v) max_v = showp[i][t]; if (showp[i][t] < min_v) min_v = showp[i][t]; } mexprintf("Maximum is %f, Minimum is %f\n", max_v, min_v); for (i = 0; i < M; i++) for (t = 0; t < STEPS; t++) fprintf(outfile, "%f ", (show[i][t]-min_v)/(max_v-min_v)); fclose(outfile); /* outfile = fopen("Speech", "w"); for (i = 0; i < Ms; i++) for (t = 0; t < STEPS; t++) fprintf(outfile, "%f ", (shows[i][t]-min_v)/(max_v-min_v)); fclose(outfile); outfile = fopen("Phone", "w"); for (i = 0; i < Mp; i++) for (t = 0; t < STEPS; t++) fprintf(outfile, "%f ", (showp[i][t]-min_v)/(max_v-min_v)); fclose(outfile); */ fclose(out); void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { inputs(); connections(); initiate(); evaluate(); store(); } float rnd() /* returning a value in (0, 1) */ { return(rand()/(MAXVAL - 1.0)); } float lateral(i,j) /* determine lateral connections */ int i, j; { int k; float temp1 = 0.0, temp2 = 0.0, base = 0.05; for (k = 0; k < N1; k++) if (k != i && ext2[k][j] != ext2[i][j] && branch[k][j] && ext[i][j] > 0) { if (W[i][j][k] > base) temp1 = We; else if (W[i][j][k] < -base) temp2 = Wi; } if (temp2 < -base) return(Wi); else if (temp1 > base) return(We); else return(0.0); } float getxx(y,br) /* br: branch */ float y; int br; { float temp, cat; /* solving cubic equation */ cat = -0.5*(y-2.0); if (y > 0.0 && y < 4.0) { temp = acos(cat); if (br) return(2*cos(temp/3.0)); else return(2*cos(temp/3.0+0.66*3.1416)); } else { temp = 0.5*sqrt(y*y-4.0*y); if (cat - temp > 0.0) return(pow(cat+temp,0.333) + pow(cat-temp,0.333)); else if (cat + temp > 0.0) return(pow(cat+temp,0.333) - pow(-cat+temp,0.333)); else return(-pow(-cat-temp,0.333) - pow(-cat+temp,0.333)); } } float getx(y,br) /* piecewise linear version */ float y; int br; { if (y > 0.0 && y < 4.0) { if (br) return(-0.25*y+2.0); else return(-0.25*y-1.0); } else { if (y > 0.0) return(-0.25*y-1.0); else return(-0.25*y+2.0); } }
Code:
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
72 mex group.c Warning group.c: 227 local `float angle' is not referenced Warning group.c: 323 missing return value Warning group.c: 442 local `int num' is not referenced Warning group.c: 441 local `float cat' is not referenced Warning group.c: 441 local `float angle' is not referenced Warning group.c: 441 local `float xval' is not referenced Warning group.c: 441 local `float current' is not referenced Error group.c: 611 illegal statement termination Error group.c: 611 skipping `void' Error group.c: 611 illegal expression Error group.c: 611 syntax error; found `nlhs' expecting `)' Error group.c: 611 insufficient number of arguments to `mexFunction' Error group.c: 611 syntax error; found `nlhs' expecting `;' Error group.c: 611 undeclared identifier `nlhs' Error group.c: 611 illegal use of type name `mxArray' Error group.c: 611 undeclared identifier `plhs' Error group.c: 611 illegal expression Error group.c: 612 illegal expression Error group.c: 612 syntax error; found `nrhs' expecting `]' Error group.c: 612 type error: pointer expected Error group.c: 612 operands of * have illegal types `incomplete struct mxArray_tag defined at C:\PROGRA~1\MATLAB\R2010A\extern\include\matrix.h 293' and `int' Warning group.c: 612 reference to `incomplete struct mxArray_tag defined at C:\PROGRA~1\MATLAB\R2010A\extern\include\matrix.h 293' elided Warning group.c: 612 Statement has no effect Error group.c: 612 syntax error; found `nrhs' expecting `;' Error group.c: 612 undeclared identifier `nrhs' Error group.c: 612 illegal expression Warning group.c: 612 Statement has no effect Error group.c: 612 syntax error; found `mxArray' expecting `;' Error group.c: 612 illegal use of type name `mxArray' Error group.c: 612 undeclared identifier `prhs' Error group.c: 612 too many errors C:\PROGRA~1\MATLAB\R2010A\BIN\MEX.PL: Error: Compile of 'group.c' failed. ??? Error using ==> mex at 222 Unable to complete successfully. >> mex group.c Warning group.c: 227 local `float angle' is not referenced Warning group.c: 323 missing return value Warning group.c: 442 local `int num' is not referenced Warning group.c: 441 local `float cat' is not referenced Warning group.c: 441 local `float angle' is not referenced Warning group.c: 441 local `float xval' is not referenced Warning group.c: 441 local `float current' is not referenced Error group.c: 611 illegal statement termination Error group.c: 611 skipping `void' Error group.c: 611 illegal expression Error group.c: 611 syntax error; found `nlhs' expecting `)' Error group.c: 611 insufficient number of arguments to `mexFunction' Error group.c: 611 syntax error; found `nlhs' expecting `;' Error group.c: 611 undeclared identifier `nlhs' Error group.c: 611 illegal use of type name `mxArray' Error group.c: 611 undeclared identifier `plhs' Error group.c: 611 illegal expression Error group.c: 612 illegal expression Error group.c: 612 syntax error; found `nrhs' expecting `]' Error group.c: 612 type error: pointer expected Error group.c: 612 operands of * have illegal types `incomplete struct mxArray_tag defined at C:\PROGRA~1\MATLAB\R2010A\extern\include\matrix.h 293' and `int' Warning group.c: 612 reference to `incomplete struct mxArray_tag defined at C:\PROGRA~1\MATLAB\R2010A\extern\include\matrix.h 293' elided Warning group.c: 612 Statement has no effect Error group.c: 612 syntax error; found `nrhs' expecting `;' Error group.c: 612 undeclared identifier `nrhs' Error group.c: 612 illegal expression Warning group.c: 612 Statement has no effect Error group.c: 612 syntax error; found `mxArray' expecting `;' Error group.c: 612 illegal use of type name `mxArray' Error group.c: 612 undeclared identifier `prhs' Error group.c: 612 too many errors C:\PROGRA~1\MATLAB\R2010A\BIN\MEX.PL: Error: Compile of 'group.c' failed.
L'information se trouve dans le message d'erreur :
Il manque une accolade fermante } juste avant la ligne 611 du fichier group.cError group.c: 611 illegal statement termination
D'autre part, il faut impérativement un P majuscule à mexPrintf
C'est bon Merci : )