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:
Related
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
How can I convert a txt file (that has n rows of data) with the following format:
"header1","header2","header3"
1.20,2,3
2.03,3,4
1.05,5,6
8.20,9,4
etc.
into a mat file that's simply a 2xn matrix that ignores the first row and first column of the text file and essentially transposes the other columns:
2 3 5 9
3 4 6 4
There are many ways to do that, but one function in particular allows starting the read at a given row and column offset simply in the calling parameter (without having to specify headerlines or adding * in format specifier): The function dlmread
In your case, it's a simple matter of calling it with the right parameters:
M = dlmread( 'test.txt' , ',' , 1 , 1 ).' ;
M =
2 3 5 9
3 4 6 4
The nice thing about this function is it returns a double array directly (useful if you only want to read numbers), instead of a cell array like some other functions.
Note that I transposed the result at the end of the line (using the transpose operator .'), to get it the way you wanted.
Also note that the last 2 parameters are considered offset (as opposed to start row index). It means a value of 1 specify an offset of 1, so the reading will start at row index 2 (first index is 1).
I have created 800 Poisson distributed random numbers. then write those numbers in a .txt file. I want to write my each data value in new line like,
1
2
3
but it is coming like
1 2 3..
I used dlmwrite as,
dlmwrite('rts2_data.txt',rts2, '\t');
Which delimiter should I use to take each data value in new line?
I don't know specifically about Matlab, but \t is the tabulation character.
If you want a new line, perhaps you could use the new line character, \n, or maybe \r\n if it does allow more than one character (\r is a "carriage return").
Ok, so Matlab doesn't allow to place the new line character directly as delimiter. Instead, you can use this syntax:
dlmwrite('rts2_data.txt', rts2, 'delimiter', ' ', 'newline', 'pc');
As seen here. You can also check out this page which documents the parameters available for the dlmwrite function.
You can arrange the data as a column vector initially (not a row). dlmwrite tries to keep a matrix structure you have.
Here is my working example:
z=[0 1 2 3]
dlmwrite('rts2_data1.txt',z)
dlmwrite('rts2_data2.txt',z')
and the outputs of the files are:
rts2_data1.txt
0,1,2,3
rts2_data2.txt
0
1
2
3
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.
I am trying to read a text file into matlab where the text file has been designed so that the columns are right-aligned so that my columns look like,
3 6 10.5
13 12 9.5
104 5 200000
This has given me two situations that I'm not sure how to handle in matlab, the first is the whitespace before the first data and the other is the variable number of whitespace characters in each row which seems to be beyond my knowledge of textscan. I'm tempted to use sed to reformat the text file but I'm sure this is trivial to someone. Is there a way that I can an arbitrary amount of whitespace as the delimeter (and have the line start with the delimeter)?
Use regexp on every line.
M = regexp(str, '\w+(\d+)','tokens')
Use the load command:
l = load('C:\myFile.txt')
It will work as long as you have only numbers, and same number of columns.