Jump to content

Plot data

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1
nedsana

nedsana

    Newbie

  • Members
  • Pip
  • 3 posts
Hi,

I have created a GDI application which has to display some signals on the screen (sin wave, square wave, etc). I have a display with a set size(for example 640x480). The data that I plot is taken from a 1d array of doubles. After some calculations I create 2d array from it and I plot this one. And so far everything is working fine.

The problems is that the user should be able to specify the length of the input data. For example the user specifies that the input array is 1000 elements, and the display is 640 points wide.

How can I resize the data, so that it fits exactly in the display? What kind of tricks/algorithms can I use?


I came up with a solution but it is not a nice one. What I currently do is for example:
- the display is 640 pixels
- the data is 6400 values

So: data/pixels = 6400/640 = 10, which means that every tenth value occupies a new pixel on x-axes of the display. These ten values that are inbetween occupy pixels on the y-axes of the display.

Now if the data is 1000 values, I will plot it, but the last couple of pixels on the display will remain empty.

I am looking for suggestions?

Thank you in advance,
Greetings, Nedelin.

#2
josep

josep

    Learning Programmer

  • Members
  • PipPipPip
  • 56 posts
Try to use Vectors instead of arrays and resize the pixels with respect to user input. Because if you store your values in an array, there is no way to resize it other than creating a new one.
Hope it helps!

#3
nedsana

nedsana

    Newbie

  • Members
  • Pip
  • 3 posts
Hi,

I don't want to change the number of the pixels of the display.

I write this program in simple C. There are no vectors and stuff. Besides I am not really used to vectors, and honestly prefer to avoid them.

I am looking for some standarts for creating plots. Some general guidelines.

#4
josep

josep

    Learning Programmer

  • Members
  • PipPipPip
  • 56 posts
Sorry, thought you were using Java, can u check this link,
256-Color VGA Programming in C

There are nice examples that can give u an idea of what to do

Cheers!

#5
nedsana

nedsana

    Newbie

  • Members
  • Pip
  • 3 posts
Thank you,

I will take a look at you link.