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

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

Related

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{:,:}

Export certain columns from a Matlab matrix

I have a Matlab Matrix and would like to know if there is a way to extract certain columns from this to make a new matrix.
For example, if i have a matrix of;
data=1:20
I would like to export data from columns 1,2, 9,10 and make a new matrix file.
I would like to scale this up to a matrix of about 4,400 columns...so if there is a way to select columns at defined points (like every 8th and 9th column), then that would be super!
Any help would be greatly appreciated!
Thanks,
Aj
The example you've given can be done like this:
x=data([1,2,9,10]);
You can get every 8th column like this:
index=8;
x=data(index:index:end);
If you want every 8th and 9th column and to maintain the order:
index1=8;
index2=9;
x=data(sort([index1:index1:end index2:index2:end]));
if you also want to grab individual columns or rows similar process can be used and then concatenate the into a matrix
x=data(:,2) % get the 2nd column
y=data(:,8) % get the 8th
z=[x;y] or z=[x:y] % combine them
If you table is standard you can predefine them in a small script

Creating a set matrix size

I have results which are 6 columns long however have been printed as 2 then 3 beneath then 1 beneath that! There are hundreds of lines and matlab will not except the structure of the matrix as it is now. Is there any way to tell matlab i want the first 5 results in their own columns then continuing down the rows after that?
My results appear as follows:
0.5 0
0.59095535915335684063 -0.59095535915335395405 -5.89791913085569763
33e-08
... repeated alot
thansk so much, em xx
I would just do a format shortE before you process the output, this will give you everything in scientific notation with 4 digits after the decimal. That 'should' allow you to fit your columns all in one line, so you don't have to deal with the botched output.
In general you should not want the output to be in a too specific format, but suppose you have this matrix:
M =[0.5 0 0.59095535915335684063 -0.59095535915335395405 -5.89791913085569763 33e-08];
To make it an actual matrix I will repeat it a bit:
M = repmat(M,10,1);
Now you can ensure that all six columns will fit on a normal screen by using the format.
format short
Try help format to find more options. Now simply showing the matrix will put all columns next to eachother. If you want one column below, the trick is to reduce your windows width untill it can only hold five columns. Matlab will now print the last column below the first.
M % Simply show the matrix
% Now reduce your window size
M % Simply show it again
This should help you display the numbers in matlab, if you want to process them further you can consider to write them to a file instead. Try help xlswrite for a simple solution.

labeling x-axis with cell array

I have been searching various forums for hours but it seems impossible to do a thing in Matlab that's automatic in excel...
I used uiimport to import an xls file with into two arrays (? total newbie), one containing dates for my x-axis and the other the values I want to plot.
I have 180 values. The dates are three dates per month, more or less ranging from May 2008 until now, end of March.
Using
plot(mynumbers)
set(gca,'XTickLabel',dates)
only puts dates for May 2008 on my x-axis!
where did all the other dates go?
Instead using
plot(mynumbers)
set(gca,'XTick',mynumbers,'XTickLabel',dates)
gives error message
"??? Error using ==> set
Values must be monotonically increasing."
Please help!
where did all the other dates go?
The answer to your first question is that MATLAB only uses the first N number of strings corresponding to the default N number of tick marks on the x axis.
"??? Error using ==> set Values must be monotonically increasing."
The error is telling you that your date ticks must be evenly spaced. Instead of using dates corresponding to your actual data points, you could grab the x tick values that MATLAB automatically assigned to your graph, translate them to text, and then reassign the dates as x tick labels, like so:
% generate example unevenly spaced date vector
time = [now,now+1,now+25,now+28.5,now+36,now+40,now+51,now+65];
% generate random data points
data = rand(size(time));
% plot time vs data, storing the axes handle in the process
figure;
axH = axes;
plot(axH,time,data)
% get the x-axis tick locations
ticLoc = get(axH,'XTick');
% format tick labels (substitute any date format you wish)
ticLab = cellfun(#(x) datestr(x,'mm/dd'),num2cell(ticLoc),'UniformOutput',false);
% apply tick labels
set(axH,'XTickLabel',ticLab)
MATLAB's built-in function datetick also performs similarly.
However, if you zoom afterwards, you won't have accurate tick labels. So you may want to use datetick2 on the File Exchange.
If you're having trouble converting a cell array of dates from Excel into a numeric array, use:
dateNumeric = cell2mat(cellfun(#datenum,dateStrings,'UniformOutput',false));
try set (gca,'XTickLabel',num2str(dates))

Core Plot skipped values Graph

i'm trying to draw a Graph with a user-friendly timeline having every day/week (to be decided by time range) as a label at x-axis. However, the datasource values are given on another basis - there might be 10 entries one day and the eleventh comes in a month.
See the photoshop image:
With the latest Core Plot drop I cannot find a way to do it, need your help.
Regards,
user792677.
The scatter plot asks the datasource for x-y pairs of data. There is no requirement that either value follow some sort of sequence or regular pattern. Other plot types work similarly, although the names and number of data fields can vary.
In your example, return 4 from the -numberOfRecordsForPlot: method. Return the following values from the -numberForPlot:field:recordIndex: method. The table assumes your y-values are calculated by a function f(x), but they can of course come from any source. Use the field parameter to determine whether the plot is asking for the x- or y- value.
Index X-Value Y-Value
0 1 f(1)
1 3 f(3)
2 9 f(9)
3 10 f(10)