Ploting data with gnuplot - bash

I have 3 columns and 1000 rows of integers in .dat file and I have to plot it in the graph in the way that first column is on the x-axes and sqrt(c2²+c3²) is on the y-axes, where c2 is from the second column and c3 is from the third column, using gnuplot script.
Normally I use something like plot <somefile.dat> using 1:2 but now I have to use second and third column somehow like that using 1:sqrt(2²+3²).

To construct equations from column values from your datafile, gnuplot provides a parenthesis grouping, e.g. (your equation here). In order to define your equation within parenthesis, you refer to the column value wanted by prefixing the column number with a '$' (e.g. $2 refers to the value from column 2, $3 refers to the value from column 3, etc..) and you can use those references as many times as needed within the parenthesis and each use will be replaced by the value from the numbered column.
In your case to have the 1st column be your independent x-values and your equation result the dependent value drawing the numbers from columns 2 & 3, you can do:
plot "somefile.dat" using 1:(sqrt($2*$2+$3*$3))
A short example with the input file as:
$ cat somefile.dat
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
6 6 6
7 7 7
8 8 8
9 9 9
10 10 10
Creating a short plot file for convenience:
$ cat some.plt
plot "somefile.dat" using 1:(sqrt($2*$2+$3*$3))
You can generate your plot with
$ gnuplot -p some.plt
Look things over and let me know if this is what you needed.

Related

Output All Rows of a File Whose 3rd and 4th Line are Within a Certain Range of the 3rd and 4th Columns of Another File

I am looking for help with filtering through a few thousand star brightnesses I have on text files. I have two text files (both of the same star field, just different filters), each file has four columns:
Column 1 - Brightness |
Column 2 - Uncertainty |
Column 3 - X coordinate |
Column 4 - Y coordinate |
The x and y coordinates for the stars in each filter can be slightly off though... So I am looking to use a code similar to something like:awk -F'|' 'NR==FNR{c[$3$4]++;next};c[$3$4]' file1 file2 > output.txt but that can find matches for the 3rd and 4th columns within 1.5 units between the two images.
Essentially, I am looking for a way to compare two columns and print the row if it is within the +/- 1.5 range of the other file's columns. Any ideas would be hugely appreciated. Thank you.

reorder array of Strings with minimal DB update operations

Lets say im storing some ordered strings like this:
1 apple
2 banana
3 pear
4 mango
5 cantaloupe
Now I need to insert strawberry that should show up at position 4.
OFC I can easily do that by updating numeric index, ex:
1 apple
2 banana
3 pear
4 strawberry
5 mango
6 cantaloupe
But the issue is - if I need to store this position update in the database I now need to store 3 operations:
a) UPDATE index = 6, WHERE index=5
b) UPDATE index = 5, WHERE index=4
c) insert strawberry at position 4
Which is fine for small lists, but in large lists I would end up with a large number of position update operations.
Is there a more efficient approach? Maybe using something other than numbers?

How to find a recurring pattern into a list of numbers?

I need a way to find pattern in list of values. In particular every second I get a value in a range (ex. 1-3), and I want to find recurring pattern from this value list.
If i plot this values into an x,y system i'd get something like a Nyquist–Shannon sampling. It could be very interesting to work on this.
I could also plot these values and work on visual pattern recognition (neural networks...).
input:
instant value
1 1
2 2
3 3
4 1
5 2
6 3
7 1
output->1,2,3
What could be the best way to proceed ?

Finding non-continuous numbers in an array

I was wondering if you had a column like
[8 8 8 8 8 1 4 4 4 1 1]'
What code could I write to find the numbers that are not repeated consecutively (non-contiguous)? In this case, what code would I have to write to find row 6? This is for big data.
--Dwight

Can Any of You Draw the Interleaved 2 of 5 Barcode Type for the Following Number?

I'd doing some tests with the barcode generator I made and when I input some bill barcode numbers for simulating, it draws fine but just in the beginning of the barcode. the sequence of black and white stripes just match with the ones shown in the beginning of the printed bill. in some bills it keeps matching till some pairs of numbers ahead, then it looses matching. that's why I'd like some of you to draw a barcode of interleaved 2 of 5 type regarding the following binary number, so I can compare with mine: 10100100011001000110110001001000000110111100000011. this sequence is the decimal number 3419157411. or separated by pairs.
34 = 1010010001
19 = 1001000110
15 = 1100010010
74 = 0000011011
11 = 1100000011
thanks in advance.
I got "101011101110100010100011101000101000111011100010100010111010101000111011100011100010101011100011101"
You can use my Int 2of5 generator. Set the width to at least 8 and make sure to select Interleaved 2 of 5 from the dropdown.
If you want to check your barcode against an existing barcode generator, try bwip-js at http://metafloor.github.io/bwip-js. It has on online generator that supports several variations of 2 of 5 code, including interleaved. (Disclosure: I am the author of bwip-js.)

Resources