I have 2 CSV files with over 80k strings in each.
The first file have this structure:
12.11.12 - 00:59:58;428,8;
12.11.12 - 00:59:59;428,9;
...
12.11.12 - 21:53:32;592,7;
12.11.12 - 21:53:35;596,4;
...
14.11.12 - 12:31:41;510,0;
14.11.12 - 12:31:41;510,0;
And the second have another scructure:
1;428.9;
1;428.9;
5;428.9;
...
117109;673.6;
117110;672.8;
117111;672.8;
...
214241;497.2;
214241;497.2;
214258;507.3;
How I can plot both of this CSV files in Gnuplot?
P.S. The first column must be x and the second must be y.
First, apparently you can set the delimiter thus:
set datafile separator ";"
Then set the time format for your first file, and set x to be a time axis:
set timefmt "%d.%m.%y - %H:%M:%S"
set xdata time
Plot the first file
plot "data1.csv" using 1:2
The second file x values don't seem to have a date format, but instead perhaps seconds elapsed? For that, just do
set datafile separator ";"
plot "data2.csv" using 1:2
and don't set xdata time. Then you should have an x axis in seconds. If you need to plot both at the same time, it would be simplest to pre-process one to look like the other.
Related
I got a problem reading some data from a txt file. I appreciate any suggestion and thank you in advance!
I have a txt file with text/number on top, followed by two tab-separated columns (additionally, they have commas instead of dots).
I want to extract the two columns without text, and replace the commas with dots in order to plot them.
I tried with importdata to be able to replace the commas, but it separates every single character, so I get 36k elements instead of 2048.
Tried dlmread but it ignores the second column...
I have no idea how to proceed without modifying every single file manually.
here is an example of the file:
Data from FLMS012901__118__10-30-26-589.txt Node
Date: Tue Jul 05 10:30:26 CEST 2022
User: Myself
Number of Pixels in Spectrum: 2048
>>>>>Begin Spectral Data<<<<<
338,147 -2183,94
338,527 -2183,94
338,906 -2183,94
339,286 -2251,25
Any suggestions?
EDIT:
Apparently, there was already a solution, even though a bit slow:
% Read file in as a series of strings
fid = fopen('data.txt', 'rb');
strings = textscan(fid, '%s', 'Delimiter', '');
fclose(fid);
% Replace all commas with decimal points
decimal_strings = regexprep(strings{1}, ',', '.');
% Convert to doubles and join all rows together
data = cellfun(#str2num, decimal_strings, 'uni', 0);
data = cat(1, data{:});
On the sample that you provide, the following works:
>> [a,b,c,d] = textread("SO_73502149.txt","%f,%f %f,%f", "headerlines", 6);
>> format free
>> [a+b/1000, c+sign(c).*d/100]
ans =
338.147 -2183.94
338.527 -2183.94
338.906 -2183.94
339.286 -2251.25
However there are some possible traps, according to the way decimal figures are handled in your file, you should adapt the post-processing: If for 338.10 338,1 is printed in the file instead of 338,10 , the decoding would be a bit harder. Whenever c becomes zero, sign(c) would kill the decimal part. A less trivial post-processing would be required.
I am new to TCL language and wish to know how can I do the following process. Assume I have a program that creates a text file per single run and should be run for 10000 times. Every single run creates and text file called "OUT.out". All I am interested is a single number in a specific column from that OUT.out file in a single run.
Ideal case for a single run should be as following:
Start the main Run, (should be repeated for 10000 times, assumed)
Run Case 1
Finish the Case 1
Open the text file, OUT.out.
Find the maximum absolute value in the 4th column of the text file.
Save the max value in a separate text file in row 1.
delete the OUT.out file
Run Case 2
Finish the Case 2 of the main loop
Open the text file, OUT.out.
Find the maximum absolute value in the 4th column of the text file.
Save the max value in a separate text file in row 2.
delete the OUT.out file
Run Case 3
Finish the Case 3 of the main loop
Open the text file, OUT.out.
Find the maximum absolute value in the 4th column of the text file.
Save the max value in a separate text file in row 3.
delete the OUT.out file
Run Case 4
.
.
.
I presume code should be shorted that my note. Thanks in advance for your help.
Depending on what the separator is, you might do:
# Read in the data and list-ify it; REAL data is often messier though
set f [open OUT.out]
set table [lmap row [split [read $f] "\n"] {split $row}]
close $f
# Kill that unwanted file
file delete OUT.out
# Tcl indexes start at 0
set col4abs [lmap row $table {
expr { abs([lindex $row 3]) }
}]
# Get the maximum of a list of values
set maxAbs [tcl::mathfunc::max {*}$col4abs]
# You don't say what file to accumulate maximums in
set f [open accumulate.out "a"]; # IMPORTANT: a == append mode
puts $f $maxAbs
close $f
and then repeat that after each run. I'm sure you can figure out how to do that bit.
But if you're doing this a lot, you probably should look into storing the results in a database instead; they're much better suited for this sort of thing than a pile of ordinary files. (I can thoroughly recommend SQLite; we moved our bulk result data management into it and greatly improved our ability to manage things, and that's keeping lots of quite big binary blobs as well as various chunks of analysable metadata.)
I have a MATLAB script that I would like to run in Octave. But it turns out that the timeseries and synchronize functions from MATLAB are not yet implemented in Octave. So my question is if there is a way to express or replace these functions in Octave.
For understanding, I have two text files with different row lengths, which I want to synchronize into one text file with the same row length over time. The content of the text files is:
Text file 1:
1st column contains the distance
2nd column contains the time
Text file 2:
1st column contains the angle
2nd column contains the time
Here is the part of my code that I use in MATLAB to synchronize the files.
ts1 = timeseries(distance,timed);
ts2 = timeseries(angle,timea);
[ts1 ts2] = synchronize(ts1,ts2,'union');
distance = ts1.Data;
angle = ts2.Data;
Thanks in advance for your help.
edit:
Here are some example files.
input distance
input roation angle
output
The synchronize function seems to create a common timeseries from two separate ones (here, specifically via their union), and then use interpolation (here 'linear') to find interpolated values for both distance and angle at the common timepoints.
An example of how to achieve this to get the same output in octave as your provided output file is as follows.
Note: I had to preprocess your input files first to replace 'decimal commas' with dots, and then 'tabs' with commas, to make them valid csv files.
Distance_t = csvread('input_distance.txt', 1, 0); % skip header row
Rotation_t = csvread('input_rotation_angle.txt', 1, 0); % skip header row
Common_t = union( Distance_t(:,2), Rotation_t(:,2) );
InterpolatedDistance = interp1( Distance_t(:,2), Distance_t(:,1), Common_t );
InterpolatedRotation = interp1( Rotation_t(:,2), Rotation_t(:,1), Common_t );
Output = [ InterpolatedRotation, InterpolatedDistance ];
Output = sortrows( Output, -1 ); % sort according to column 1, in descending order
Output = Output(~isna(Output(:,2)), :); % remove NA entries
(Note, The step involving removal of NA entries was necessary because we did not specify we wanted extrapolation during the interpolation step, and some of the resulting distance values would be outside the original timerange, which octave labels as NA).
I'm having trouble with a time based graph on gnuplot. My graph plots the data of a CSV file from a noise sensor. My CSV file is written in the following format:
Time,Decibel
08:00:28,56.5
08:00:30,55.5
08:00:31,59.6
08:00:33,61.8
And so on.
My gnuplot script looks like this:
set datafile separator ","
set autoscale fix
set key outside right center
set xdata time
set timefmt '"%H:%M:%S"'
set xrange ['"08:00"':'"18:00"']
set terminal png
set output "/home/pi/Desktop/Codes/Graph/Picture/graph.png"
set title "Graph"
plot '/home/pi/Desktop/Codes/Graph/Values/2017-02-08.csv' using 1:2 with lines
What am I doing wrong? And is it possible to set the X to be every hour between 08:00 to 18:00?
that seems to be caused by the double quotes in:
set timefmt '"%H:%M:%S"'
set xrange ['"08:00"':'"18:00"']
try something like:
set timefmt "%H:%M:%S"
set xrange ["08:00:00":"18:00:00"]
As for the x-tics, one can set the beginning in the same notation as the xrange and then specify the step in seconds. For example to show a tic every 2 hours:
set xtics "08:00:00",2*3600
(Or, in fact, even set xtics "08:00:00","02:00:00" seems to work)
I have a GNUplot script that works perfectly with tab separated data, but my data comes in .csv files and it would be really handy to read them direct, any ideas?
Here is a sample of data in comma seprated.csv format, the other is exactly the same but in a .txt and obviously tab by a comma rather than a tab
HEADER
HEADER
Timestamp,Date,Time,Value,Units
1413867843,21/10/2014,05:04:03,0.053,µA
1413867243,21/10/2014,04:54:03,0.091,µA
1413866643,21/10/2014,04:44:03,0.084,µA
1413866043,21/10/2014,04:34:03,20.000,µA
1413846241,20/10/2014,23:04:01,0.041,µA
1413845641,20/10/2014,22:54:01,0.056,µA
1413845041,20/10/2014,22:44:01,0.123,µA
1413844441,20/10/2014,22:34:01,20.000,µA
1413824638,20/10/2014,17:03:58,0.075,µA
1413824038,20/10/2014,16:53:58,0.073,µA
1413823438,20/10/2014,16:43:58,0.103,µA
1413822838,20/10/2014,16:33:58,20.000,µA
Here is the problematic GNUPlot script I use
CSV MIN
#!/gnuplot
set terminal pdf enhanced font "sans,6"
#Filename
set output "BIOSENSE GRAPH TEMPLATE.pdf"
set size ratio 0.71
set pointsize 0.1
set datafile separator ","
#DATA FILES
plot 'ACT.csv' using 1:4 every::6 title 'Active' with points pt 5 lc rgb 'red' axes x1y1
And finally this is the error message I get from GNUplot
line 15: x range is invalid
Any help appreciated!
Thanks