tags:

views:

57

answers:

3

Hi

I am storing samples using a text file in my C program. I want to plot a waveform using those values in excel. How can I export data to excel from program???How can I do that??? otherwise Is there any other way to plot waveform in C program itself???

Thanks in advance...

A: 

There is a way if you save an HTML file with a table with the XLS extension, Excel will open it. Then you can make your graph using the data.

Basically, save a file with

<html>
<body>
  <table>
    <tr>
      <td>Cell</td>
      <td>Cell</td>
      <td>Cell</td>
    </tr>
    <tr>
     <td>Cell</td>
     <td>Cell</td>
     <td>Cell</td>
    </tr>
 </table>
</body>
</html>
Daniel A. White
Is there no way other than excel???give me idea on HTML file
ulaganathan
You could also use a C library that writes excel files, but this is a simple one to understand.
Daniel A. White
Thanks for ur suggestion.....Is it possible to call excel API's from C program?
ulaganathan
+1  A: 

Since you seem to be open to alternatives, may I suggest Gnuplot. It's a very flexible plotting software that can be easily controlled via pipes. If all you want is to plot some graphs, it's likely much easier to use than the behemoth that is Excel.

Controlling Gnuplot from your own software involves starting it up as a new process and feeding commands into stdin. It has a built-in help function for the commands, and extensive documentation available on the site I linked to. In order to plot some data generated by your program, you could feed it something like this:

set term x11 persist
plot '-' using 1:2 with lines
1 2
2 3
3 2.5
5 1
e

This example is for Linux, and shows the plot in a new window that persists after the controlling program has exited, which is handy if you just want to look at the graph. The set term line can be changed to adapt for other platforms, or to have it save the output into a file instead (there are many output formats, including PNG and SVG).

Here's an example graph I just created by using

set term png
set output "a-graph.png"

and then running the above plot command.

Example graph

Matti Virkkunen
yes.....please tell about Gnuplot...
ulaganathan
A: 

Most plot programs (including gnuplot and excel, I think) are able to read simple formats that have all values for a point on one line and that separates these by commas or tab-characters. A simple printf format for a point could look like this:

printf("%g\t%g\t%g\n", x, y, z);

If you want to store the data with another precision than printed by the default, you'd have to look into the man page.

Jens Gustedt