简体   繁体   English

绘制和显示数组的简单方法?

[英]Easy way to plot and display arrays?

First post here. 在这里的第一篇文章。 Using C in Visual Studio 2008. Can work with VS 2005 if necessary. 在Visual Studio 2008中使用C。必要时可以与VS 2005一起使用。

  1. How do I display numerical data in arrays as in a spreadsheet? 如何像在电子表格中那样在数组中显示数值数据?
  2. How do I plot numerical data in arrays? 如何在数组中绘制数字数据?

These seem to be simple questions. 这些似乎是简单的问题。 But I cannot find solutions. 但是我找不到解决方案。 So far, I would print the data to a file, import into Excel and view/plot. 到目前为止,我将数据打印到文件中,导入到Excel中并查看/绘制。 However, with this code there are too many arrays--so the print/import/plot is tiring. 但是,使用此代码,数组太多了,因此打印/导入/绘图很累人。 Some constraints. 一些约束。

  1. I do not want to write 20+ lines of code to do the above. 我不想编写20多行代码来完成上述操作。 MATFOR or Array Visualizer let you do the plotting with a one line function call. MATFOR或Array Visualizer使您可以通过一行函数调用进行绘制。
  2. They cannot display the data in a convenient format. 他们无法以方便的格式显示数据。 I would like to display the data and the plot in one or two windows so that they are visible simultaneously. 我想在一个或两个窗口中显示数据和图表,以便它们同时可见。
  3. This is a win32 console application---all the code is portable. 这是一个win32控制台应用程序-所有代码都是可移植的。
  4. Will be using these during debugging. 将在调试过程中使用它们。
  5. Free or paid. 免费或付费。

While I am looking for something specific, the requirements are substantially the same for any one doing numerical work with arrays and matrices--displaying data and plot simultaneously. 当我在寻找特定的东西时,对使用数组和矩阵进行数值运算的任何人的要求基本上是相同的-同时显示数据和绘图。 I am hoping that a such a tool has been written and is available. 我希望已经编写了这样的工具并且可以使用。 I am also open to a solution that outputs the array data to an Excel sheet (can keep Excel open) and if it can also plot that can be great but I can live without plotting. 我也对将数组数据输出到Excel工作表(可以使Excel保持打开状态)的解决方案持开放态度,如果它还可以绘制出可以很好的图形,但我可以不绘制图形而生活。

PS: I need this only when debugging the code. PS:仅在调试代码时才需要。

I use ArrayDebugView which is a plug-in you install in Visual studio and draws graphs out of arrays while you are debugging your application. 我使用ArrayDebugView ,它是您安装在Visual Studio中的插件,可以在调试应用程序时从数组中绘制图形。 It works as a visual way of variable watch in debug mode. 在调试模式下,它是可视化的变量监视方式。 You don't need to write a line of code. 您无需编写任何代码。

I made a simple plotting program for that purpose. 为此,我编写了一个简单的绘图程序。 There is only a textbox where I paste the data and a chart where it's drawn. 我只在其中粘贴数据的文本框和绘制数据的图表。

The data needs to be in either form: 数据必须采用以下两种形式:

  • with an automatic X (increment by 1 for each value): seriesName value 自动X(每个值加1): seriesName值
  • for both X and Y specified: seriesName xvalue yvalue 对于指定的X和Y: seriesName xvalue yvalue

Most of the time I used to plot data from tracepoints. 大多数时候,我以前都是从跟踪点绘制数据。 I copy/paste the whole output window of VS, the plotting program ignores anything that doesn't follow these 2 forms (so I don't have to cleanup the string and put it in excel and all). 我复制/粘贴了VS的整个输出窗口,绘图程序会忽略不遵循这两种形式的任何内容(因此,我不必清理字符串并将其放在excel等中)。

It does line, point, colum, area charts and save image, copy to clipboard. 它可以绘制折线图,​​点图,列,面积图并保存图像,然后复制到剪贴板。

在此处输入图片说明

MiniPlot MiniPlot

There are several ways to do this but this will require writing some code. 有几种方法可以做到这一点,但这需要编写一些代码。 Visualizing data is generally easy and straight forward but visualizing data exactly the way you want them to look will require some additional code and work. 可视化数据通常很容易且直接,但是要完全按照所需的方式可视化数据将需要一些额外的代码和工作。

There are several options to visualize data: 有几种可视化数据的选项:

A combination of BASH and GNUPLOT BASH和GNUPLOT的组合

Use MATLAB or OCTAVE for all your calculations and visualization 使用MATLAB或OCTAVE进行所有计算和可视化

Use PYTHON and SciPy and matlibplot libraries. 使用PYTHON,SciPy和matlibplot库。

Gnuplot is a great tool to plot data but it is cumbersome to use. Gnuplot是绘制数据的好工具,但使用起来很麻烦。 It looks fabulous if you invest time to get the plots right and combines excellent with LaTeX and has a good fit implementation for arbitrary functions. 如果您花费时间来正确绘制图表,并且与LaTeX完美结合,并且可以很好地实现任意功能,那么它看起来很棒。 Visit http://gnuplot-tricks.blogspot.ch/ great site to learn all about gnuplot. 访问http://gnuplot-tricks.blogspot.ch/这个很棒的网站,以了解有关gnuplot的所有知识。

Numerical programs such as MATLAB and it's open source equivalent OCTAVE are great because they are fast implementation languages for numerical programs and have extensive additional libraries especially MATLAB. 诸如MATLAB之类的数字程序及其等效于OCTAVE的开源程序之所以出色,是因为它们是数字程序的快速实现语言,并且具有广泛的附加库,尤其是MATLAB。 For high load numerical computing it is really slow and the plot library is only good for basic plotting needs. 对于高负荷数值计算,它确实很慢,并且图库仅适合基本绘图需求。

Using PYTHON and its scientific programing libraries (SciPy and matlibplot) are a great combination. 使用PYTHON及其科学程序库(SciPy和matlibplot)是一个很好的组合。 This allows excellent plot which are not as cryptic as gnuplot to plrogram and it is more flexible than MATLAB in plotting. 这样可以实现出色的绘图,而对于prrogram而言,它不如gnuplot神秘,并且在绘图方面比MATLAB更灵活。 Additionally it gives you a environment for numerical programing like MATLAB. 此外,它还为您提供了像MATLAB这样的数值编程环境。

I can't think of any library that would enable what you want in a console app in less than 20 lines of code. 我想不出任何可以用不到20行代码就能在控制台应用程序中实现所需功能的库。 My suggestion would be instead to script the plotting-step using MATLAB og GNU Octave to do the actual plotting. 我的建议是改为使用MATLAB和GNU Octave编写绘图步骤,以进行实际绘图。

In order to display numerical data in array, you should add the pointer to the first data element you want to observe, into the watch --- if you want to observe the array from the beginning, it would just be the array name, which is the pointer to the first element. 为了在数组中显示数值数据,您应该将指向要观察的第一个数据元素的指针添加到手表中---如果要从头开始观察数组,则将其作为数组名称,即是指向第一个元素的指针。 In order to view more then one element, you add a "," after the pointer, followed by the number of element you want to observe. 为了查看一个以上的元素,您可以在指针后面添加一个“,”,后跟要观察的元素的数量。 For example, in order to observe the elements of float farray[100]; 例如,为了观察float farray[100];的元素float farray[100]; , you should add to the watch farray,100 . ,您应该将其添加到手表farray,100

In order to plot, you can copy-paste from the watch to your plotting software (ie excel), but it is not very convenient as you cannot copy the data column alone, but the columns to the left and right as well, so it involves extra manual editing. 为了进行绘图,您可以将手表上的粘贴内容复制到绘图软件(即excel)中,但是这样做并不方便,因为您不能单独复制数据列,但也可以复制数据列的左右两边。涉及额外的手动编辑。

I use GNUPlot (http://www.gnuplot.info/) to display my performance/speedup measurements. 我使用GNUPlot(http://www.gnuplot.info/)来显示性能/加速指标。 I print my numbers to stdout and wrote a bash script that combines these numbers and calls gnuplot for rendering. 我将数字打印到stdout并编写了一个bash脚本,将这些数字组合起来并调用gnuplot进行渲染。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM