LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I read X data from one file (.txt), Y data from another file (.txt) and plot a fit of the graph?

I have two files (.txt), one with the X values  and the other (.txt) with the Y values.
Both the files are like this:
 
34
54
76
89
...
 and the number of rows is of course the same in both cases.
 
I want to read them, find a fit for the curve and then have the values of the fit curve disposable for plotting them or for further elaboration.
 
I have tried using "read from spreadsheet.vi" and the "curve fitting" block but I experienced several problems.
 
What can I do?
Thank you very much.
 
Best Regards,
Emanuele Cornagliotti 
 
 
0 Kudos
Message 1 of 5
(3,103 Views)

You would need two separate Read From Spreadsheet functions but if you are using the Curve Fitting Express VI, then you need to convert the x and y data to a dynamic data type. You do this and wire to the Signals and Locations inputs. Instead, you can use the lower level curve fittings functions (i.e. Linear Fit) which accept separate x and y arrays as inputs.

Message Edited by Dennis Knutson on 02-19-2007 09:37 AM

0 Kudos
Message 2 of 5
(3,094 Views)
This is actually what I did. I used the curve fitting module (using a spline interpolant) and i converted the data to the dynamic data type:
The problem that I experienced are the following:
1) If I plot the output I always get a graph with time on the X-axis (see picture attachment). In practice the shape of the graph seems correct but the values of the X-axis have nothing to do with the real values I have in the file (Injection levels_Si.txt) and moreover they are labelled as "time". The other file I have attached (Mobility_Sum_Si.txt) is the Y axis.
2) Even if I set in the "read from spreadsheet.vi" the path of those two files I always have to re-input them every time I run my .vi. Instead, I would like to make the program read always from those two files without asking during its execution.
 
How can I do?
 
Thank you!!!!!!!
 
Emanuele Cornagliotti
 
 
Download All
0 Kudos
Message 3 of 5
(3,071 Views)
Always regarding point 1). In practice what I get on the X-scale are the progressive indexes of my Y-Values (I have 45 values indeed).
0 Kudos
Message 4 of 5
(3,062 Views)

The 'time' and 'Amplitude' on a graph are just labels. Double click on the text to change it. You can also go to the graph's properties and the Scales tab to change the Name.

I apologize - I only showed part of the process. If you use the low level functions (top part in my example) this only returns an x array. To plot the new curve with the original x, just bundle them together and wire to an XY graph. You can also overlay the original XY plot. I haven't used the express function but you can take the output of the express curve fitting and wire that to the Y input of the express XY graph and the x input would be the same that you wired to the locations input.

If you don't want to keep being prompted for file names, just create a constant. On the diagram and on the path input, right click and select 'Create>Constant'. You could also have a front panel control with the paths defined. Right click on a control and select Data Operations>Make Current Value Default. After you do this, you have to save the VI.

0 Kudos
Message 5 of 5
(3,040 Views)