NOTE

This tutorial assumes you already know how to write text to a file. If you aren't sure, please review and understand FileIO.

Introduction

We want to get our cool new hotplate data into Excel so we can graph it. In this little tutorial, we'll use a smaller example file to show the steps.

Your Code

How to Output to a .CSV file

In your code, the only change you need to make is in the output file name. Instead of “.txt”, use “.csv.” <syntaxhighlight lang=“cpp” line start=“1” highlight=“13” >

    ofstream myfile ("example.csv");
</syntaxhighlight>

As long as you are printing your output like the following, Excel will be able to open it:

0.0,100.0,100.0,100.0,0.0,
0.0,45.1,60.6,66.2,0.0,
0.0,45.1,60.6,66.2,0.0,
0.0,100.0,100.0,100.0,0.0,

(Yours will be much bigger. The point is the *comma seperated values* arranged row by row.)

Finding the Output File

The default location for your output file is the lab's project folder inside the workspace folder

Excel

Opening the file

If you double click on your .CSV file, Excel should open up and show you something like this:

The Chart

Select your table of values. Then click the “Insert” tab and find “Other Charts” in the Charts group. The one we want is the first one under “Surface.”

Tweak it

Click “Switch Row/Column” if your view of the graph isn't very good. Also, another color is not required, but you can change it under “Chart Styles.”

cs-142/plot-the-results.txt · Last modified: 2015/01/07 15:55 by ryancha
Back to top
CC Attribution-Share Alike 4.0 International
chimeric.de = chi`s home Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0