0

I have a text file where I get my values,

I have a timer which works as an increaser to the x axis so the plot is real time.

here's my code.

void gui::x()
{
    int xy = 0;

    QVector<double> x(1000), y(1000);
    FILE *file;

    char line[1024];
    file = fopen("x.txt", "r");

    while (fgets(line,1024,file) != NULL)
    {
        fscanf(file,"%lf %lf", &y[xy], &x[xy]);
        xy++;
    }

    fclose(file);

    QwtPlotCurve *curve = new QwtPlotCurve;
    curve->attach(plot_all[3]);
    curve->setData(y,x);
    curve->

    QwtPlotCurve *curve2 = new QwtPlotCurve;
    curve2->attach(plot[3]);
    curve2->setData(y,x);
}

the proble is i get a weird second line below my plot.

can anyone help me?

ecg

SamuelNLP
  • 4,038
  • 9
  • 59
  • 102
  • Your code is a) incomplete, and b) uncompilable even virtually due to obvious typos. Please provide a minimal, self-contained example of you issue so that you can help us help you, and chances are you've already helped yourself in the process. – rubenvb Nov 03 '16 at 10:22

1 Answers1

0

I solved it by using an array instead of a vector.

void gui::ecg()
{
    int xy = 0;

    double x[1000], y[1000];
    FILE *file;

    char line[1024];
    file = fopen("ecg.txt", "r");

    while (fgets(line,1024,file) != NULL)
    {
        fscanf(file,"%lf %lf", &y[xy], &x[xy]);
        xy++;
    }

    fclose(file);

    QwtPlotCurve *curve = new QwtPlotCurve;
    curve->attach(plot_all[0]);
    curve->setData(x,y,1000);
    curve->setPen(QPen(Qt::blue,1));

    QwtPlotCurve *curve2 = new QwtPlotCurve;
    curve2->setStyle(QwtPlotCurve::Lines);
    curve2->attach(plot[0]);
    curve2->setData(x,y,1000);
    curve2->setPen(QPen(Qt::blue,1));
}
SamuelNLP
  • 4,038
  • 9
  • 59
  • 102