I want to use system call(s) to grab values from first data line in file file and print into legend of plot.
The command returns a syntax error. I admit come confusion about a- the use of system calls and syntax, despite reading few advanced questions here.
This is what I have:
gnuplot> plot for [i=20:30:1] '4He-processed' index i u 8:($22>0.2&&$22<2?$9:1/0):10 w yerr t system("head -2 4He-processed | tail -1 | awk '{printf "%s %8.3f %8.3f %s" , "'", $3, $4,"'"}'")
with the response: ')' expected with the pointer at the "f" in printf.
I want to have the values in $3 and $4 written to the legend.
This alternate command
gnuplot> plot for [i=20:30:1] '4He-processed' index i u 8:($22>0.2&&$22<2?$9:1/0):10 w yerr t system("head -2 4He-processed | tail -1 ")
puts the entire first line, of each index loop, to the legend
It likely has to do with syntax?
I want the values from $3 and $4, not the column headings:
Here is the some lines (but not all the columns) from the file
nz na e0 theta nu xsect ert y fy fye
2 4 0.150 60.000 0.025 0.330E+02 0.752E+00 -0.0459 0.956E+00 0.218E-01
2 4 0.150 60.000 0.030 0.497E+02 0.784E+00 -0.0001 0.146E+01 0.230E-01
2 4 0.150 60.000 0.035 0.483E+02 0.766E+00 0.0315 0.144E+01 0.229E-01
2 4 0.150 60.000 0.040 0.408E+02 0.728E+00 0.0573 0.125E+01 0.224E-01
This continues for many blocks. Here, if I were to start my loop with the first block, the values (at $3 and $4) would be 0.150 and 60.000 which correspond to the energy and angle of the projectile and they would hopefully appear in the legend. The plotted quantities ($8,$22 and $23) not pasted here (too many columns).
The problem is that the double-quoted string in your command starts with head" and runs to printf". That is clearly not what you intended.
Also I am uncertain what you mean by values in $3 and $4. Can you show an example of the first line (2 lines?) of your file and state, in words, what you are trying to extract from it?
Amended answer after seeing the data and a fuller explanation of the requirements
The answer from #theozh should work, but for completeness here is a different approach that works in either gnuplot 5.2 or 5.4.
It uses two passes through the data file; one pass to construct the titles, and a second pass for the actual plot.
$Data <<EOD
nz na e0 theta nu xsect ert y fy fye
1 11 0.150 60.000 5 6 7 8 9 10
2 12 0.150 60.000 5 6 7 8 9 10
3 13 0.150 60.000 5 6 7 8 9 10
4 14 0.150 60.000 5 6 7 8 9 10
nz na e0 theta nu xsect ert y fy fye
1 21 0.250 65.000 5 6 7 8 9 10
2 22 0.250 65.000 5 6 7 8 9 10
3 23 0.250 65.000 5 6 7 8 9 10
4 24 0.250 65.000 5 6 7 8 9 10
nz na e0 theta nu xsect ert y fy fye
1 31 0.350 70.000 5 6 7 8 9 10
2 32 0.350 70.000 5 6 7 8 9 10
3 33 0.350 70.000 5 6 7 8 9 10
4 34 0.350 70.000 5 6 7 8 9 10
EOD
set key out
set key title "e0 theta" left
#set datafile columnheader # omit this line for gnuplot version < 5.4
# columheaders are not actually used anyhow
#
# First pass is just to accummulate an array of titles
#
nblocks = 30 # maximum number of data blocks
array Title[nblocks] # one title for each data blockA
set term push # remember current terminal
set term dumb # could be anything
set out '/dev/null' # throw away the output
plot for [i=0:2:1] $Data index i using 1:2:($0 == 1 ? Title[i+1]=sprintf("%g %g",$3,$4) : "") with labels
#
# Second pass is the actual plot
#
set term pop # restore original terminal
plot for [i=0:2:1] $Data index i using 1:2 with lp title Title[i+1]
I guess you can't use columnheader() (check help columnheader), because by this you will sacrifice the first data line of each block and I assume you do want to keep all data.
The following should work for gnuplot>=5.4.0 and under the assumption that column 3 and 4 do not change within each block. However, this will not work for gnuplot<=5.4.0, because (as I understand) the title for the legend will be evaluated before each plotting iteration and in gnuplot>=5.4.0 after each plotting iteration. For gnuplot<5.4.0 you have to think about other workarounds.
I hope you get the idea and can adapt the script to your case, i.e. filtering, etc.
Script: (works for gnuplot>=5.4.0)
### extract title without using columnheader()
reset session
$Data <<EOD
nz na e0 theta nu xsect ert y fy fye
1 11 0.150 60.000 5 6 7 8 9 10
2 12 0.150 60.000 5 6 7 8 9 10
3 13 0.150 60.000 5 6 7 8 9 10
4 14 0.150 60.000 5 6 7 8 9 10
nz na e0 theta nu xsect ert y fy fye
1 21 0.250 65.000 5 6 7 8 9 10
2 22 0.250 65.000 5 6 7 8 9 10
3 23 0.250 65.000 5 6 7 8 9 10
4 24 0.250 65.000 5 6 7 8 9 10
nz na e0 theta nu xsect ert y fy fye
1 31 0.350 70.000 5 6 7 8 9 10
2 32 0.350 70.000 5 6 7 8 9 10
3 33 0.350 70.000 5 6 7 8 9 10
4 34 0.350 70.000 5 6 7 8 9 10
EOD
set key out
plot for [i=0:2:1] $Data u 1:2:(myTitle=sprintf("%g, %g",$3,$4)) index i \
w p pt 7 ps 2 lc i title myTitle
### end of script
Result:
Addition: (script for gnuplot>=4.6.0, March 2012)
What Ethan did in his answer with an array (available only from 5.2.0 on) you can do with strings and word() for older versions (check help word).
The following works for 4.6.0 and 4.6.5 and >=5.0.0, however, not for 4.6.7 (it complains that ... '+' u (NaN):(NaN) ... "Skipping data file with no valid points").
For gnuplot 4.x you cannot add spaces in your myTitles, but for gnuplot>=5.0.0 you could use double quotes and include spaces, e.g. myTitles=myTitles.sprintf(' "%g, %g"',$3,$4).
You might have to adapt the color numbers in the second plot command depending on which subblocks (index) you are plotting in the first plot command.
Data: SO74320605.dat
nz na e0 theta nu xsect ert y fy fye
1 11 0.150 60.000 5 6 7 8 9 10
2 12 0.150 60.000 5 6 7 8 9 10
3 13 0.150 60.000 5 6 7 8 9 10
4 14 0.150 60.000 5 6 7 8 9 10
nz na e0 theta nu xsect ert y fy fye
1 21 0.250 65.000 5 6 7 8 9 10
2 22 0.250 65.000 5 6 7 8 9 10
3 23 0.250 65.000 5 6 7 8 9 10
4 24 0.250 65.000 5 6 7 8 9 10
nz na e0 theta nu xsect ert y fy fye
1 31 0.350 70.000 5 6 7 8 9 10
2 32 0.350 70.000 5 6 7 8 9 10
3 33 0.350 70.000 5 6 7 8 9 10
4 34 0.350 70.000 5 6 7 8 9 10
Script: (works for gnuplot 4.6.0, 4.6.5, >=5.0.0, but not for 4.6.7)
### extract title from lines without using columnheader()
reset
FILE = "SO74320605.dat"
set key out noautotitle
myTitles = ''
plot for [i=0:2:1] FILE u 1:2:($0==1?myTitles=myTitles.sprintf(' %g,%g',$3,$4):0) \
index i w lp pt 7 ps 2 lc i+1, \
for [i=1:words(myTitles)] '+' u (NaN):(NaN) every ::::0 \
w lp pt 7 ps 2 lc i ti word(myTitles,i)
### end of script
Result: (created with gnuplot 4.6.0)
I used R and the rank function to create the following ranks for the original var x:
x average first last random max min
3 4.5 4 5 5 5 4
1 1.5 1 2 2 2 1
4 6.0 6 6 6 6 6
1 1.5 2 1 1 2 1
5 8.0 7 9 9 9 7
9 11.0 11 11 11 11 11
2 3.0 3 3 3 3 3
6 10.0 10 10 10 10 10
5 8.0 8 8 7 9 7
3 4.5 5 4 4 5 4
5 8.0 9 7 8 9 7
I am struggling to implement the min-version in MQL5. First, you probably need to sort the Array but you need to take care of the original order. How the ranks are assigned manually is quite logical but I have no clue how to implement this in MQL5.
Stat2Data package contains a lot of exemplary datasets. I get no errors when installing it or using the library function to call it. However, it doesn't allow me to work with the objects.
Anyone familiar with this package and know what I can do about it? Here's the code that I used:
install.packages("Stat2Data")
library(Stat2Data)
# Attempt 1
MedGPA_ds <- ggplot(MedGPA, aes(x = GPA, y = Acceptance))
# Attempt 2
MedGPA_ds <- ggplot(Stat2Data::MedGPA, aes(x = GPA, y = Acceptance))
You have missed just one step, the use of the data() function to call the specific dataset (MedGPA) contained within the Stat2Data package.
Try the following:
library(Stat2Data)
data(MedGPA)
head(MedGPA)
Accept Acceptance Sex BCPM GPA VR PS WS BS MCAT Apps
1 D 0 F 3.59 3.62 11 9 9 9 38 5
2 A 1 M 3.75 3.84 12 13 8 12 45 3
3 A 1 F 3.24 3.23 9 10 5 9 33 19
4 A 1 F 3.74 3.69 12 11 7 10 40 5
5 A 1 F 3.53 3.38 9 11 4 11 35 11
6 A 1 M 3.59 3.72 10 9 7 10 36 5
Happy coding!
I have a file with these values:
9 10 11 9.5 10.2 9.8 10 8.7 9.3 9.1 9 8.9
4 5 5 4 6 5 4 3 4 5 5 4
8 11 10 8.5 10.7 9 11 8.5 9.4 9 10 9.9
5 5 5 5 5 5 5 5 5 5 5 5
9 9 9 9 9 9 9 9 9 9 9 9
4 5 5 4 6 5 4 3 4 5 5 4
8 9 10 8.5 9.2 8.8 9 7.7 8.3 8.1 8 7.9
7 4 6 6 6 5 6 6 6 6 5 6
10 11 12 10 11.2 9 11 9.7 9 9.1 10 9.9
6 5 6 6 6 5 6 6 6 6 5 6
10 9 11.2 9.5 10.8 9 10.3 8 9.3 9.1 9 8.9
5 4 5 4 6 5 4 3 4 5 5 4
9 10 10.4 8.5 10.2 9.2 11.1 8 9.4 9 10 9.9
6 4 5 5 5 5 5 5 5 5 5 5
10 8 9.6 9 9.6 9.7 9 9 9.7 8 10 9
5 4 5 4 6 5 4 3 4 5 5 4
9 8 10.8 8.5 9.5 8 9.5 7 8.3 8.1 8.8 9
5 4 5 4 6 5 4 3 4 5 5 4
11 10 11 10 11.3 9.4 11 9 9.5 8 10 7
4 5 5 4 6 5 4 3 4 5 5 4
I need to accept these values into an array, so I can then get the largest number out of every other line, and the lowest out of the other lines.
Say I make an array
float array[20][12];
This doesn't seem to work:
fscanf(ifp, "%f", &main_array[20][12]);
So how can I accept these values into my array?
you need to read value by value, using a loop, you could make something like this:
float array[20][12];
int n = 20 * 12;
int i;
for(i = 0; i < n; i++)
fscanf(ifp, "%f", (&array[0][0] + i));
That's because you cannot read all file at once.
Another way, and maybe more easy to understand(because not uses pointer arithmetic) is:
int i, j;
for(i = 0; i < 20; i++)
for(j = 0; j < 12; j++)
fscanf(ifp, "%f", &array[i][j]);
I want to apply the median of medians algorithm to a list of 35 elements
3 7 4 6 9 12 11
4 5 6 8 2 7 11
23 12 4 7 3 9 8
4 5 6 3 2 1 9
9 3 4 5 6 1 14
T(n) <= T(n/5) + T(7n/10) + O(n) fails.
Can you explain why?
http://classes.soe.ucsc.edu/cmps102/Spring05/selectAnalysis.pdf
This pdf explains it. Spend some time on it. You will get it. Its easy.