GnuPlot chart drawing for each text file - charts

I compare four kind of sorting algorithms, and their inversions and comparisions for each algorithm are stored in a file. What I need now is to draw a scatter with markers (x,y) for each file where
x -> number of inversions
y -> number of comparisions
and scale it to the numbers, so for example we have IS10.txt which stands for InsertionSort and it has 300 lines with x's and y's.
Sample data
line 1: 20 33
line 2: 18 27
...
line 300: 21 24
The key is to be able to generate diagrams for comparison.

Plotting a single file is straightforward, just use
plot 'IS10.txt' using 1:2 title 'InsertionSort'
If you want to plot all files, you can do it as follows:
list = system('ls -1 *.txt | tr "\n" " "')
set key out
plot for [file in list] file using 1:2 title file
Here, I assumed, that all .txt files in the current directory should be plotted. You could of course also generate the list manually. It should contain all file names, delimited by a space (e.g. list = "IS10.txt HS10.txt ...").
That plots all data points of one file with the same linetype. The first file uses linetype 1, the second one linetype 2 etc. Type test to see how the points and colors of these default linetype look like.
You can use something like set linetype 1 linecolor rgb 'blue' pointtype 7 to change these settings in order to get 20 well-distinguishable point styles.

Related

gnuplot scatter plot selecting data on range of value in 3rd Column

In a Windows 7 environment, I need to do a gnuplot scatter plot of 2 columns selecting data based on a range of values in a 3rd column. I know how to do it by creating separate data files for each range, but is it possible to do it by filtering on the data value in a 3rd column without awk
Thanks
plot "<awk '{if($3>=11 && $3<=19) print $0}' plot.dat " using 1:2 with points
warning: Skipping data file with no valid points
I Presume the error is because I don't have awk in windows7 envirenment
There are (should be) many examples of filtering data with gnuplot here on StackOverflow, however, mostly combined with another issue. So, whenever I'm trying to search for a really good and clear example, it takes more time for searching than to simply write down the line.
You definitely don't need awk!
Attention: Filtered data will not be connected in a line plot. So, in case you want to plot connected filtered lines, e.g. with lines or with linespoints you need to prepend an extra line. I assume you have gnuplot>=5.0.
For older gnuplot versions you can check this workaround.
The following will plot column 1 versus column 2, but only if column 3 is in the range 11 to 19.
set datafile missing NaN
plot "myData.dat" u 1:($3>=11 && $3<=19 ? $2: NaN) w linespoints

gnuplot - how to read the & character from dat file

I am reading a .dat File and one of headings of a Column contains the & character. When I try to plot the columns via Gnuplot the & character disapears in the name of the function. I am using the columnheader function to get the name. How do I have to adjust the name of the Column?
Current Column headings:
i D&C
You can double escape the & character in the data file like this:
i D\\&C
1 4
2 3
3 5
Now the plot command works:
plot "a.dat" w lp title columnheader
This is the result:

skipping of several line and start reading only numbers [duplicate]

This question already has answers here:
Reading a text file in MATLAB line by line
(5 answers)
Closed 6 years ago.
let us suppose we have following table
% El-Centro earthquake signal:
% North-south component recorded at Imperial Valley Irrigation District
% substation in El Centro, California, during the Imperial Valley,
% California earthquake of May, 18, 1940. The magnitude is 7.1. and the maximum ground acceleration is 0.3495g
%
% Time (sec) Acceleration (g)
0.0000000e+00 1.1000000e-03
2.0000000e-02 1.1000000e-03
4.0000000e-02 1.3000000e-03
6.0000000e-02 1.4000000e-03
8.0000000e-02 1.3000000e-03
1.0000000e-01 1.2000000e-03
it is just fragment, i would like to create two dimensional table, one for time and second for acceleration,first of all we should skip text lines, i have tried following command
M = dlmread('ELCENTRO.txt', ' ', 6, 0);
that means i have skipped 6 row, but after i got matrix with dimension of
size(M)
ans =
2829 7
based on result i have done another command
M = dlmread('ELCENTRO.txt', ' ', 6, 3);
and now dimension of M changed
size(M)
ans =
2829 4
now i can do following thing
M(:,2:3)=[];
now M contains two column, one for time and second for signal, but how can i do this using dlmread command? thanks in advance
dmlread is a pretty old function with few bells and whistles. It appears that it won't work for your file as you have a 2 character delimiter (i.e. two spaces between the numbers).
But even if it did work, you're better off using tables for this type of data.
tbl = readtable('ELCENTRO.txt','HeaderLines',6,'ReadVariableNames',false,'Format','%f %f')
You then want to change the column names,
tbl.Properties.VariableNames = {'Time','Acceleration'}
In many cases the names could be read from the file, but the format of your file precludes that.
If you're not used to using tables then see the following as a starting point on how to manipulate them,
docsearch('Access Data in a Table')
In particular, if you do really just want the data as a matrix then do,
M = tbl{:,:}

The dlmread command

I am trying to load ascii files into Matlab which contain 1020 rows and two columns of spectral data. When I use dlmread like below, Matlab turns this into a matrix N, which is what I want:
N = dlmread('alummatrix.asc')
However, I want it to read only the first 80 rows of data and ignore the rest, and then do this for all .asc files in a directory.
Also, I want the decimal number not to change or get rounded. It's outputting my data 5 decimal figures to the left of the original data. Also, I'd like it to retain its original notation and not to round:
It gives me:
N =
1.0e+05 *
0.0384 0.3374
When I just want it to show up like:
N =
3838 33738
Use this line of code:
N = dlmread('alummatrix.asc','',[0 0 80 0]);
Good luck!

reading in text file and organising by lines using MATLAB

I want to read in a text file (using matlab) with data that is not in a convenient matlab matrix form. This is an example:
{926377200,926463600}
[(48, 13), (75, 147), (67, 13)]
{926463600,926550000}
[(67, 48)]
{926550000,926636400}
[]
{926636400,926722800}
[]
{926722800,926809200}
...
All I would like is a vector of all the numbers separated by commas. With them always being in pairs and the odd lines' numbers are of much greater magnitude each time, this can be differentiated by logic later.
I cannot figure out how to use textscan or the other methods. What makes this a bit tricky is that the matlab methods require a defined format for the strings separated by delimiters and here the even lines have non-restricted numbers of integer pairs.
You can do this with textscan. You just need to specify the {} etc as whitespace.
For example, if you put your sample data into the file tmp.txt (in the current directory) and run the following:
fid = fopen('tmp.txt','r');
if fid > 0
numbers = textscan(fid,'%f','whitespace','{,}[]() ');
fclose(fid);
numbers = numbers{:}
end
you should see
numbers =
926377200
926463600
48
13
75
147
67
13
926463600
926550000
67
48
926550000
926636400
926636400
926722800
926722800
926809200
Just iterate through each character. (use fscanf or fread or whatever). If the character is a number (use str2num) , store it as a number , if it is not a number, discard it and start storing a new number when you encounter the next number.