Plotting a graph with Koolplot

This is a discussion on Plotting a graph with Koolplot within the C Programming forums, part of the General Programming Boards category; I'm trying to plot a graph using koolplot, but nothing happens when I try to run the program. Anybody here ...

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    6

    Plotting a graph with Koolplot

    I'm trying to plot a graph using koolplot, but nothing happens when I try to run the program. Anybody here knows how to use koolplot?


    Here's the code:
    Code:
    #include <koolplot.h>
    #include <stdio.h>
    
    void graph(double g);
    
    int main()
    {
    	 double a = 5.5, b = 2.5, gh;
    	 
    	 gh = a / b;
         
    	 graph(gh);	
    
             return 0;
    }
    
    
    
    void graph(double g)
    {
    	plotdata x(-10, 10);
    	plotdata y = g;
    	plot(x,y);
    }
    Any help would be much appreciated, thanks!

  2. #2
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    i see alot of references to quincey, do you have it?
    http://codecutter.org/tools/quincy/index.html

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    6
    Quote Originally Posted by nadroj
    i see alot of references to quincey, do you have it?
    http://codecutter.org/tools/quincy/index.html
    Yeah, thats how I came up with the codes. But for some reason it didn't work, any ideas why?

  4. #4
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    your using quincy to compile it? if so and still doesnt work then i dont know as ive never used it

  5. #5
    Registered User
    Join Date
    Oct 2006
    Posts
    6
    Quote Originally Posted by nadroj
    your using quincy to compile it? if so and still doesnt work then i dont know as ive never used it
    Yeah, i'm using quincy. And thanks for trying anyway.

  6. #6
    Mistake is a way to learn
    Join Date
    Sep 2006
    Location
    Malaysia
    Posts
    11
    Maybe i can help out.
    Whats the error when u compile it?

  7. #7
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    ok i installed quincy and got it working, kind of an unusual 'IDE'.

    heres how:

    1 open quincy
    2 file > new > project
    3 fill in target name and path, select 'koolplot' application
    4 click 'ok'
    5 for the window that pops up right click and 'insert file'
    6 browse to your source code (ie .c/.cpp file)
    7 click build or run or whatever, it should pop up.

  8. #8
    Mistake is a way to learn
    Join Date
    Sep 2006
    Location
    Malaysia
    Posts
    11
    I think there is some problem with the source code though.
    -The plotdata is case sensitive.
    So, it should be Plotdata
    -Um.. I don't know what u're assigning to your Y-Axis. I think you shouldn't put only a single value inside the axis.
    -Like nadroj said, you must assign a koolplot project to your source code first.

  9. #9
    Registered User
    Join Date
    Oct 2006
    Posts
    6
    I already have a project file but it doesn't work. And the weird thing is that I cant even build the program, so I don't know whether there's anything wrong with my source code. And did you guys manage to get it working? It would be nice if you could show me an example or two.
    Last edited by Router; 11-02-2006 at 03:26 AM.

  10. #10
    Mistake is a way to learn
    Join Date
    Sep 2006
    Location
    Malaysia
    Posts
    11
    can u get the most simple graph to work?

    Code:
    #include<stdio.h>
    #include<koolplot.h>
    
    int main()
    {
       Plotdata x(0,90);
       Plotdata y = x * x;
    
       plot(x,y);
    
       return 0;
    }
    If this code doesn't work, then the problem is in your quincy.

  11. #11
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    see my post 7.

  12. #12
    Registered User
    Join Date
    Oct 2006
    Posts
    6
    Thanks for the tips guys, I wrote some new codes just now and got the program to compile. But there seems to be something wrong with the koolplot function I wrote.

    The following error popped up, Any ideas what's going on?
    graph.c:24 error: cannot convert 'double' to 'double' for argument '1' 'void graph(double*, int)'
    Here's the source code
    Code:
    #include <stdio.h>
    #include <koolplot.h>
    #define A 100
    
    void graph(double num[], int z);
    int main()
    {
    
    int col, z=0, n=0;
    double col2[A], half[A];	
    FILE *data;	   
    	
    data = fopen("textfile.txt", "r");	 
    
    while (fscanf(data, "%lf %lf", &col, &col2[z]) == 2)
           {
    	   
    	  half[n] = col2[z]/2;  
              printf("\n%d %lf\n", col, half[n]);
    	  graph(half[n], col);	  
    			
    	  z++;
    	  n++;		   
           }
    	   
    fclose(data);
    return 0;
    }
    
    /* Is there something wrong with the function? */
    
    void graph(double num[], int z)
    {	 
    	Plotdata x(0, 20);
    	Plotdata y(num, z);
    	plot(x,y);
    }
    the text file I'm using:
    Code:
    0.5 301.232
    1.5 311.311
    2.5 321.123
    3.5 282.776
    4.5 569.650
    5.5 554.225
    6.5 196.213
    7.5 1221.128
    8.5 770.550
    9.5 922.232

  13. #13
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    your function is defined as:
    Code:
    void graph(double num[], int z);
    then you call it like this:
    Code:
    graph(half[n], col);
    do you see whats wrong?

    col is an 'int'
    is 'half[n]' a 'double[]'?

  14. #14
    Mistake is a way to learn
    Join Date
    Sep 2006
    Location
    Malaysia
    Posts
    11
    Even though if you fix that error, i think you're getting runtime error there.
    Here is how it should have done. Look thoroughly, and try to understand.

    Code:
    #include<stdio.h>
    #include<koolplot.h>
    
    int main()
    {
    	int i, count;
    	double col1 ,col2;
    	FILE *filePtr;
    	
    	Plotdata x,y;
    	
    	filePtr = fopen("textfile.txt","r");
    	
    	if(filePtr == NULL) printf("Error.....\n");
    	
    	while(fscanf(filePtr,"%lf %lf",&col1,&col2) == 2)
    		point(x,y,col1,col2);
    		
    	fclose(filePtr);
    	
    	plot(x,y);
    	
    	return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. plotting a graph
    By cracker in forum C Programming
    Replies: 4
    Last Post: 09-23-2009, 06:37 AM
  2. error help making no sense
    By tunerfreak in forum C++ Programming
    Replies: 5
    Last Post: 04-17-2007, 08:55 PM
  3. Koolplot 2d Graph, how to use it???
    By jofrisutanto in forum C Programming
    Replies: 5
    Last Post: 09-09-2006, 08:24 PM
  4. graph plotting
    By wayne in forum C++ Programming
    Replies: 3
    Last Post: 05-25-2005, 03:47 AM
  5. determining a path through the graph
    By Mist in forum C Programming
    Replies: 2
    Last Post: 02-27-2005, 12:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21