26 bool pds_octave_plot_points(
const Pds::Matrix &X,
37 unsigned int PDS_OCTAVE_MARKERSIZE=10;
38 unsigned int PDS_OCTAVE_FONTSIZE=16;
39 unsigned int PDS_OCTAVE_LINEWIDTH=4;
41 if(X.IsEmpty())
return false;
42 if(Y.IsEmpty())
return false;
43 if(labelx==NULL)
return false;
44 if(labely==NULL)
return false;
45 if(imgfile==NULL)
return false;
47 char *OCTAVEFILE=NULL;
50 OCTAVEFILE=(
char*)calloc(64,
sizeof(
char));
51 if(OCTAVEFILE==NULL)
return false;
52 sprintf(OCTAVEFILE,
"temp%d.m",rand());
56 OCTAVEFILE=strdup(octfile);
57 if(OCTAVEFILE==NULL)
return false;
62 fd=fopen(OCTAVEFILE,
"w");
63 fprintf(fd,
"%c\n",
'%');
64 if(fd==NULL)
return false;
66 for(i=0 ; i<Y.Nlin() ; i++)
68 if(i!=Y.LinEnd()) fprintf(fd,
"%e\n",Y.Get(i));
69 else fprintf(fd,
"%e;\n",Y.Get(i));
73 for(i=0 ; i<X.Nlin() ; i++)
75 if(i!=X.LinEnd()) fprintf(fd,
"%e \n",X.Get(i));
76 else fprintf(fd,
"%e;\n",X.Get(i));
80 fprintf(fd,
"h=figure(1);\n");
81 fprintf(fd,
"hp=plot(X,Y,\'ob\');\n");
83 fprintf(fd,
"set(hp,\'markersize\',%d);\n",PDS_OCTAVE_MARKERSIZE);
84 fprintf(fd,
"set(hp,\'linewidth\',%d);\n",PDS_OCTAVE_LINEWIDTH);
85 fprintf(fd,
"grid on;\n");
86 fprintf(fd,
"hx=xlabel(\'%s\');\n",labelx);
87 fprintf(fd,
"hy=ylabel(\'%s\');\n",labely);
89 fprintf(fd,
"ha = gca(); \n");
90 fprintf(fd,
"FONTSIZE=%d;\n",PDS_OCTAVE_FONTSIZE);
91 fprintf(fd,
"set(hx,'fontsize',FONTSIZE);\n");
92 fprintf(fd,
"set(hy,'fontsize',FONTSIZE);\n");
93 fprintf(fd,
"set(ha,'fontsize',FONTSIZE);\n");
95 fprintf(fd,
"refresh();\n");
96 fprintf(fd,
"saveas (h,\'%s\');\n",imgfile);
101 orden=(
char *)calloc(1,48+strlen(OCTAVEFILE));
102 if(orden==NULL)
return false;
103 sprintf(orden,
"octave --no-gui -q %s",OCTAVEFILE);
114 bool pds_octave_plot_vector(
const Pds::Matrix &X,
const char *labelx,
const char *labely,
const char *octfile,
const char *imgfile)
120 unsigned int PDS_OCTAVE_MARKERSIZE=10;
121 unsigned int PDS_OCTAVE_FONTSIZE=16;
122 unsigned int PDS_OCTAVE_LINEWIDTH=4;
124 if(X.IsEmpty())
return false;
125 if(labelx==NULL)
return false;
126 if(labely==NULL)
return false;
127 if(imgfile==NULL)
return false;
129 char *OCTAVEFILE=NULL;
132 OCTAVEFILE=(
char*)calloc(64,
sizeof(
char));
133 if(OCTAVEFILE==NULL)
return false;
134 sprintf(OCTAVEFILE,
"temp%d.m",rand());
138 OCTAVEFILE=strdup(octfile);
139 if(OCTAVEFILE==NULL)
return false;
144 fd=fopen(OCTAVEFILE,
"w");
145 fprintf(fd,
"%c\n",
'%');
146 if(fd==NULL)
return false;
148 for(i=0 ; i<X.Nlin() ; i++)
150 if(i!=X.LinEnd()) fprintf(fd,
" %e, %e \n",X.Get(i,0),X.Get(i,1));
151 else fprintf(fd,
"%e, %e;\n",X.Get(i,0),X.Get(i,1));
155 fprintf(fd,
"h=figure(1);\n");
156 fprintf(fd,
"hp=plot(X(:,1),X(:,2),\'ok\');\n");
157 fprintf(fd,
"daspect([1 1 1]);\n");
158 fprintf(fd,
"set(hp,\'markersize\',%d);\n",PDS_OCTAVE_MARKERSIZE);
159 fprintf(fd,
"set(hp,\'linewidth\',%d);\n",PDS_OCTAVE_LINEWIDTH);
160 fprintf(fd,
"grid on;\n");
161 fprintf(fd,
"hx=xlabel(\'%s\');\n",labelx);
162 fprintf(fd,
"hy=ylabel(\'%s\');\n",labely);
164 fprintf(fd,
"ha = gca(); \n");
165 fprintf(fd,
"FONTSIZE=%d;\n",PDS_OCTAVE_FONTSIZE);
166 fprintf(fd,
"set(hx,'fontsize',FONTSIZE);\n");
167 fprintf(fd,
"set(hy,'fontsize',FONTSIZE);\n");
168 fprintf(fd,
"set(ha,'fontsize',FONTSIZE);\n");
170 fprintf(fd,
"refresh();\n");
171 fprintf(fd,
"saveas (h,\'%s\');\n",imgfile);
176 orden=(
char *)calloc(1,48+strlen(OCTAVEFILE));
177 if(orden==NULL)
return false;
178 sprintf(orden,
"octave --no-gui -q %s",OCTAVEFILE);
189 bool pds_octave_plot_vector(
const Pds::Matrix &X,
const Pds::Vector &Y,
const char *labelx,
const char *labely,
const char *octfile,
const char *imgfile)
195 unsigned int PDS_OCTAVE_MARKERSIZE=10;
196 unsigned int PDS_OCTAVE_FONTSIZE=16;
197 unsigned int PDS_OCTAVE_LINEWIDTH=4;
199 if(X.IsEmpty())
return false;
200 if(Y.IsEmpty())
return false;
201 if(labelx==NULL)
return false;
202 if(labely==NULL)
return false;
203 if(imgfile==NULL)
return false;
205 char *OCTAVEFILE=NULL;
208 OCTAVEFILE=(
char*)calloc(64,
sizeof(
char));
209 if(OCTAVEFILE==NULL)
return false;
210 sprintf(OCTAVEFILE,
"temp%d.m",rand());
214 OCTAVEFILE=strdup(octfile);
215 if(OCTAVEFILE==NULL)
return false;
220 fd=fopen(OCTAVEFILE,
"w");
221 fprintf(fd,
"%c\n",
'%');
222 if(fd==NULL)
return false;
224 for(i=0 ; i<Y.Nel() ; i++)
226 if(i!=Y.LinEnd()) fprintf(fd,
"%e\n",Y.Get(i));
227 else fprintf(fd,
"%e;\n",Y.Get(i));
231 for(i=0 ; i<X.Nlin() ; i++)
233 if(i!=X.LinEnd()) fprintf(fd,
" %e, %e \n",X.Get(i,0),X.Get(i,1));
234 else fprintf(fd,
"%e, %e;\n",X.Get(i,0),X.Get(i,1));
238 fprintf(fd,
"ID0=find(Y<0.5);\n");
239 fprintf(fd,
"ID1=find(Y>=0.5);\n");
240 fprintf(fd,
"X0=X(ID0,:);\n");
241 fprintf(fd,
"X1=X(ID1,:);\n");
242 fprintf(fd,
"h=figure(1);\n");
243 fprintf(fd,
"hp=plot(X0(:,1),X0(:,2),\'or\',X1(:,1),X1(:,2),\'^b\');\n");
244 fprintf(fd,
"daspect([1 1 1]);\n");
245 fprintf(fd,
"set(hp,\'markersize\',%d);\n",PDS_OCTAVE_MARKERSIZE);
246 fprintf(fd,
"set(hp,\'linewidth\',%d);\n",PDS_OCTAVE_LINEWIDTH);
247 fprintf(fd,
"grid on;\n");
248 fprintf(fd,
"hx=xlabel(\'%s\');\n",labelx);
249 fprintf(fd,
"hy=ylabel(\'%s\');\n",labely);
251 fprintf(fd,
"ha = gca(); \n");
252 fprintf(fd,
"FONTSIZE=%d;\n",PDS_OCTAVE_FONTSIZE);
253 fprintf(fd,
"set(hx,'fontsize',FONTSIZE);\n");
254 fprintf(fd,
"set(hy,'fontsize',FONTSIZE);\n");
255 fprintf(fd,
"set(ha,'fontsize',FONTSIZE);\n");
257 fprintf(fd,
"refresh();\n");
258 fprintf(fd,
"saveas (h,\'%s\');\n",imgfile);
263 orden=(
char *)calloc(1,48+strlen(OCTAVEFILE));
264 if(orden==NULL)
return false;
265 sprintf(orden,
"octave --no-gui -q %s",OCTAVEFILE);