Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.graphics.apps.gnuplot > #3845
| Newsgroups | comp.graphics.apps.gnuplot |
|---|---|
| Date | 2018-01-04 10:56 -0800 |
| Message-ID | <8b40094d-fd5c-452e-939d-49710009fa5d@googlegroups.com> (permalink) |
| Subject | about error message "matrix does not represent a grid" in gnuplot |
| From | Dawn <duan77084@gmail.com> |
Hi, all:
I used fopen in c to read in a data file. I used plot 'data.txt' matrix with image to plot out the image. However, when I used fopen to write in the same data set as a new data file and I used same command line with new data file as: plot 'data1.txt' matrix with image, the image cannot be plotted and error message said:
matrix does not represent a grid
My basic codes are:
------------------------------------------------------
int main()
{
#ifdef WIN32
FILE *pipe = _popen(GNUPLOT_NAME, "w");
#else
FILE *pipe = popen(GNUPLOT_NAME, "w");
#endif
int xsize = 20, ysize = 41;
float **din;
// alloc memory
din = (float **)malloc(sizeof(float *) * ysize);
for (int i = 0; i < ysize; i++) {
din[i] = (float *)malloc(sizeof(float) * xsize);
}
// read in 2D data
FILE *fp, *fp1;
fp = fopen("wedgegas.txt", "r");
fp1 = fopen("inversedwedgegas.txt", "w");
// read in data
if (fp == NULL) {
printf("fp is NULL!\n");
exit(1);
}
for (int i = 0; i < ysize; i++) {
printf("i=%d \n ", i);
for (int j = 0; j < xsize; j++) {
fscanf(fp, "%f ", &din[i][j]);
printf("%f ", din[i][j]);
}
fscanf(fp, "\n");
printf("\n ");
}
/* write final inversed data to din */
if (fp1 == NULL) {
printf("fp1 is NULL!\n");
exit(1);
}
for (int i = 0; i < ysize; i++) {
printf("%d \n", i);
for (int j = 0; j < xsize; j++) {
fprintf(fp1, "%f ", din[i][j]);
printf("%f ", din[i][j]);
}
fprintf(fp1, "\n");
printf("\n");
}
/* ---------------------------- plot results ------------------------------------------------------- */
plot:
if (pipe != NULL)
{
// plot sinc wave plot 1
fprintf(pipe, "set multiplot layout 1,2 \n"); // set multiple plots
fprintf(pipe, "plot 'wedgegas.txt' matrix with image \n"); // plot type
fprintf(pipe, "%s \n", "e"); // termination character, end a plot
fflush(pipe); // flush the pipe
fprintf(pipe, "plot 'inversedwedgegas.txt' matrix with image \n"); // plot type
fprintf(pipe, "%s\n", "e"); // termination character
fflush(pipe); // flush the pipe
// wait for key press
std::cin.clear();
std::cin.ignore(std::cin.rdbuf()->in_avail());
std::cin.get();
#ifdef WIN32
_pclose(pipe);
#else
pclose(pipe);
#endif
}
else
std::cout << "Could not open pipe" << std::endl;
fclose(fp);
fclose(fp1);
return 0;
}
------------------------------------------------------------
Any suggestions? Thanks in advance!
Back to comp.graphics.apps.gnuplot | Previous | Next | Find similar
about error message "matrix does not represent a grid" in gnuplot Dawn <duan77084@gmail.com> - 2018-01-04 10:56 -0800
csiph-web