Gnuplot: Ploting with time column [duplicate] - range

I can't seem to get gnuplot to properly plot my time data. (I'm using version 4.6, patchlevel 3.)
For an MWE (well, non-working...), the input file
reset
set xdata time
set timefmt "%H:%M:%S"
set format x "%H:%M:%S"
plot '-' using ($1):($2) with lines lw 3
15:36:12 1.0
15:43:17 3.0
16:12:02 2.0
e
produces the following output:
Apparently, gnuplot interprets the hours as seconds and ignores the rest. I have tried a bunch of other format strings (also single/double quotes), but gnuplot seems to ignore everything except the first number.
Is something wrong with my format, or is this a bug, or something else?

With $1 you explicitely select the numerical value of the first column, which bypasses any gnuplot automatism to interpret the column values as appropriate (as time value in your case). Simply use using 1:2:
reset
set xdata time
set timefmt "%H:%M:%S"
set format x "%H:%M:%S"
plot '-' using 1:2 with lines lw 3
15:36:12 1.0
15:43:17 3.0
16:12:02 2.0
e
Use the syntax $1 only when doing calculations with the actual numerical value in the respective column. $1 is a shortcut for column(1), gnuplot also knows stringcolumn(1) and timecolumn(1) for other purposes.

Related

Plotting in Matlab as the parameter value is changed

I want to plot a simple function against time. The code is below. The issue is when I change the parameter c to be 1.3 the plot does not get drawn to the whole time span that I have specified, where as if I use c to be 3.4 it draws in the whole time span.
What is it that I am doing wrong that when c=1.3 the plot stops at x=1298 (I want it to be drawn all the way up to 2000)? Is it an issue with the function that I use to generate the values?
time=0:2000;
a=10^7;
b=1000;
c=log(2)/(3.4-2.1);
d=log(2)/((6.92)*24);
values=(a*b*exp((c-d).*time))./((a-b)+b*exp(c.*time));
figure
plot(time,values)
Check your values variable in the workspace.
You will see that from the index 1300, it gets the Inf or NaN value. These values cannot be plotted. I guess the denominator gets 0 at some point.
I run your code for 1.3
When you put 1.3 , then c get negative.
c =
-0.8664
Then all the values in final formula get a very close number to zero.

How do I format the output of my MATLAB command window?

Currently looking at this API page, I have tried inputting format loose and format compact, but to no avail. What I need to do is change the way this number is displayed on the command window:
I obtain the value by rounding it to the three most significant figures in the function which I call from my main function.
stat = round(mean(v_stat),3,'significant');
I display the values through this statement:
fprintf('Ratio of Compression for Blind Deconvolution: %d \n',stat1);
I need to know how to display this value as as it's proper state instead of being multiplied by e raised to power of something.
You need to change your format statement, e.g. (a float with 3 decimals).
fprintf('Ratio of Compression for Blind Deconvolution: %.3f \n',stat1);
see the matlab help for fprintf to understand more on the format api.
Note: the %d your using is for integers

Gnuplot from 3D datafile with strange format

Hi I am looking for a quick and dirty answer,
I try to make a surface or contourplot with gnuplot from a data file. The problem is the fileformat:
Its all in one row
line 1 till line 32 contain the values for the x-coordinates 1-32 and y=1,
line 33 is the value for x=1 and y=2 and so on...
I tried to do that with the "everyline" command but since they are not separated by a blank line this is not working.
Since this data file is an output file and from my program I get many of them, it is not practicable to modify each of them. It would be best if I find a way to do that directly with gnuplot.
I also tried it with "sed" but I am not yet further than extracing values from a specific line to a specific line.
If someone could help me with a quick applicable solution for this problem, it would be great.
You could use awk to add the needed columns, e.g.,
splot "<awk '{print int(NR/32),NR%32,$1}' datafile" u 1:2:3 with points
I may have switched the x and y columns around

datetick too many output arguments

I have a time-series containing 900 entries, stored in a 900x2 matrix (first column are datenumbers converted from excel e.g. 732994 to represent 13-nov-2006, second column is the reading at each day) I would like to plot them out with the years marked out on the x-axis, using the datestr function.
here is my code segment.
x=newsgdata(:,1);
x=num2str(x); %converts datenumbers from int to string
dateline=datetick('x','yyyy');
plot(dateline,newsgdata(:,2))
when i run this code, i get the error: Error using datetick Too many output arguments.
I have tried running plot(datetick('x','yyyy'),newsgdata(:,2)) but the same error keeps popping up.
First, plot vs the datenum directly:
plot(newsgdata(:,1), newsgdata(:,2));
Then, use datetick to convert the labels from datenums to strings.
datetick('x', 'yyyy')

MATLAB num2str format

I'm storing variable values in MATLAB and putting one of the variable values as part of the file name . e.g. "Error=1e-003.mat", however different version of MATLAB gives me different format when I'm converting numbers to string using num2str command. The number 1e-3, MATLAB2011 gives me 1e-003 and MATLAB2012 gives me 1e-03.
This runs into trouble when I try to load a batch of files with a mix of those two format. Does anyone know a way to add a zero or delete a zero for the exponent so the names are consistent? Or any other ways to solve this problem?
Here's a fairly robust way to do it:
A = num2str(YOUR_NUMBER, '%0.0e');
if A(end-2)=='-' || A(end-2)=='+'
A = [A(1:end-2) '0' A(end-1:end)]; end
In words: convert the number, and check if the second-to-last character is either a '+' or a '-'. If this is so, add a '0'.
Specify a "Format string as the second argument like this:
>> disp(num2str(2920230,'%0.10e'))
2.9202300000e+006
here %0.10e means display at least 0 digits before decimal and exactly 10 digits after it in exponent form.