View Full Version : how to load data file and plot from the datafile
charu
21st March 2009, 11:41
hi
I am charu, totally New to Qwt , i have to plot from .txt file containing floating point. i want to know how to load/read a datafile and plot it row by row (that is: one value by one)
thank you for ur grt help
huseyinkozan
21st March 2009, 12:15
hi
I am charu, totally New to Qwt , i have to plot from .txt file containing floating point. i want to know how to load/read a datafile and plot it row by row (that is: one value by one)
thank you for ur grt help
Hi charu,
I also new. I wrote something similar to load data from text file:
QFile file("./data.txt");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return;
QStringList list;
QTextStream in(&file);
while (!in.atEnd()) {
list << in.readLine();
}
data = new double[list.size()];
for(int i = 0; i< list.size(); i++){
data[i] = list[i].toDouble();
}
dataSize = list.size();
And the data.txt in this format:
1.8600000e+03
1.8640000e+03
1.8660000e+03
1.8550000e+03
1.8660000e+03
1.8760000e+03
For plotting, you can look at the examples (simple plot maybe).
Good luck.
Hüseyin
charu
23rd March 2009, 12:09
thank you so much :)
Now i need to Plot the data ?
can u plz tell me how to plot? I am using QT3 and QWT5.1.1
huseyinkozan
23rd March 2009, 16:49
thank you so much :)
Now i need to Plot the data ?
can u plz tell me how to plot? I am using QT3 and QWT5.1.1
Sorry, I don't have Qt3.
Also I don't know the difference between 3 and 4.
Maybe both are same for simple things.
For plotting I am using double array, and QwtPlotCurve::setRawData() in a derived QwtPlot class.
You can also use setData().
Simply like this: (From QwtPlot Class Reference)
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
QwtPlot *myPlot;
double x[100], y1[100], y2[100]; // x and y values
myPlot = new QwtPlot("Two Curves", parent);
// add curves
QwtPlotCurve *curve1 = new QwtPlotCurve("Curve 1");
QwtPlotCurve *curve2 = new QwtPlotCurve("Curve 2");
getSomeValues(x, y1, y2);
// copy the data into the curves
curve1->setData(x, y1, 100);
curve2->setData(x, y2, 100);
curve1->attach(myPlot);
curve2->attach(myPlot);
// finally, refresh the plot
myPlot->replot();
In getSomeValues(x, y1, y2) simply copy the data to the double buffers.
Hüseyin
charu
24th March 2009, 12:08
thanks
i have error:expected constructor,destructor, or type conversion before'=' token..... hence i commented each line by line
1) no errors with include file alone
2) error started from myplot=... onwards .
i dont have any idea to solve this can you plz let me know what could be the problem on my program.
procedure i created the project:
1) New Project
2) New Widget
3) New main.cpp
copied ur code in the form1.ui.h and qmake, make ....errors plz help me
thank u in advance
huseyinkozan
24th March 2009, 20:09
thanks
i have error:expected constructor,destructor, or type conversion before'=' token..... hence i commented each line by line
1) no errors with include file alone
2) error started from myplot=... onwards .
i dont have any idea to solve this can you plz let me know what could be the problem on my program.
procedure i created the project:
1) New Project
2) New Widget
3) New main.cpp
copied ur code in the form1.ui.h and qmake, make ....errors plz help me
thank u in advance
It could be many different things; maybe header problem, or trying to reach a pointer out of scope....I don't know.
Now, its your turn to figure it out.
Act like a detective, and find the problem. Maybe you should turn back to some fundamentals.
Good luck.
Hüseyin
charu
26th March 2009, 05:45
thanks i got it :)
After incliding the lib file i can plot.
but the getSomeValues(); is not working, so i generated some x,y values and ploted
thank you so much 4r ur grt help
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.