I have several gnuplot scripts that draw graphs for me. I need to set the same xrange values on the command line for everyone gnuplot scripts.
I don't want to open each one separately.
Code in gnuplot scripts(name:tlakD.gnuplot):
set xdata time
set timefmt "%m/%d/%Y %H:%M" # specify time string format
set xrange datum
set format x "%d/%m/%Y "
Command line attempt:
gnuplot -e "datum='["1/1/19 12:00":"1/5/19 11:59"]'" tlakD.gnuplot
Second attempt:
I removed the xrange.
Code in gnuplot scripts(name:tlakD.gnuplot):
set xdata time
set timefmt "%m/%d/%Y %H:%M" # specify time string format
set format x "%d/%m/%Y "
Command line attempt:
gnuplot -e "xrange='["1/1/19 12:00":"1/5/19 11:59"]'" tlakD.gnuplot
An idea of what I want:
gnuplot -e "xrange='["1/1/19 12:00":"1/5/19 11:59"]'" tlakD.gnuplot ; vlhkosD.gnuplot; teplotaD.gnuplo and many more gnuplots scripts
I want to run all scripts with the same xrange.
Thanks
I suggest to put the range command in a separate file and invoke both the range file and the plot file in the command. You could even have a collection of range files and choose the one you want at the time of plotting.
gnuplot setrange_1.gp tlakD.gp
It is not necessary to use the -e construct here. gnuplot will execute each file listed on the command line in the order given, as if they had been concatenated into a single larger file prior to execution.
It doesn't seem you can specify a range [...:...] in one variable, but you can do so in 2 separate string variables:
gnuplot -e a='"1/1/19 12:00"' -e b='"1/5/19 11:59]"'
set xrange [a:b]
I created a data.txt file like this:
"2/1/2019 10:00:00" 4
"3/1/2019 10:00:00" 8
"4/1/2019 10:00:00" 16
"5/1/2019 10:00:00" 32
The commands I would run inside gnuplot would be:
set timefmt '"%d/%m/%Y %H:%M:%S"'
set xdata time
set xrange ['"1/1/2019 12:00"':'"1/5/2019 11:59"']
plot "data.txt" using 1:2
So, that means my bash command line would be:
gnuplot -p \
-e "set timefmt '\"%d/%m/%Y %H:%M:%S\"'" \
-e "set xdata time" \
-e "set xrange ['\"1/1/2019 12:00\"':'\"5/1/2019 11:59\"']" \
-e "plot \"data.txt\" using 1:2"
Related
I'm currently trying to use exiftool on Windows command prompt to read meta data from multiple files, then output to a single text file.
The exact command I last tried looked like this:
exiftool.exe -FileName -GPSPosition -CreateDate -d "%m:%d:%Y %H:%M:%S" -c "%d° %d' %.2f"\" -charset UTF-8 -ext jpg -w _Coordinate_Date.txt S:\Nick\Test\
When I run this, I get 7 individual text files with the content for one corresponding file in each of them. However, I simply want to output all of it to one single text file. Any help is greatly appreciated
The -w (textout) option can only be used to write multiple files. It is not meant to be used to output to a single file. As per the docs on -w:
It is not possible to specify a simple filename as an argument -- creating a single output file from multiple source files is typically done by shell redirection
Which is what you're doing with the >> ./output.txt part of your command. The -w _Coordinate_Date.txt isn't doing anything and I would think throw an Invalid TAG name: "w _Coordinate_Date.txt" error if quoted together like that as it gets treated as a single arugment. The -w option requires two arguments, the -w and either an extension or a format string.
I actually figured it out, if you wrap the entire -w _Coordinate_Date.txt command in quotations and append it to a file, you can throw all of the output into one text file.
i.e. "-w _Coordinate_Date.txt >> ./output.txt"
I have a DOS batch-file MYDOS.BAT containing:
My C-application (myApp.exe) reading an input-file (inputFile) from the DOS-command line
myApp.exe analyses inputFile and exits/returns with a code=N
How can I pass value N into my MATLAB script?
E.g: MYDOS.BAT is run by DOS>MYDOS inputFile and contains the following lines:
myApp %1
echo %ERRORLEVEL%
set samplerate=%ERRORLEVEL%
echo %samplerate%
...
C:/... matlab mymatlab.m ...
HOW CAN I THEN PASS the value %samplerate% into my mymatlab.m script?
You can use the system command to use DOS commands in Matlab. Use doc system to see the documentation.
System can have 2 outputs. The first one is a status, which will tell you if the operation succeeded. The second one is the output to the command prompt. You can parse this to get your value. You could use the following code as a guide for your situation:
[status,cmdout]=system('MYDOS.bat');
cmdout will contain the string that you are echoing to the command prompt.
I create a variable and store the day, date & time in it:
NOW=$(date "+%a %d/%m/%Y% %H:%M")
Then I would like to pass $NOW to the mv command to rename a file.
e.g. Create file named a.txt with a title and the current date:
printf "File Report (" > ~/Desktop/a.txt
echo $NOW"):\n" >> ~/Desktop/a.txt
Then I try to rename the file with the variable ($NOW) included in the name:
mv ~/Desktop/a.txt ~/Desktop/'File Report $NOW'.txt
What should that last line be? I also tried these two options.
mv ~/Desktop/a.txt ~/Desktop/'File Report' $NOW.txt
&
mv ~/Desktop/a.txt ~/Desktop/'File Report'${NOW}.txt
Assuming a reasonably Bourne-like shell (such as bash), variable substitution does not happen inside single quotes. You need to use double quotes:
mv ~/Desktop/a.txt "${HOME}/Desktop/File Report ${NOW}.txt"
(I'm not sure whether the curly braces are required, but they can't hurt)
You will also need to change the date command to avoid the use of slashes. For example:
NOW="$(date '+%a %d-%m-%Y% %H:%M')"
I'm trying to build the .NET assembly file by executing this code in matlab2010b
workdir = 'C:\Users\H\Documents\Source Code\MatlabFiles';
outdir = fullfile(workdir, 'Output');
dnetdir = fullfile(workdir, 'dotnet');
%% Determine file names
mfile = fullfile(workdir, 'perform.m');
dnetdll = fullfile(dnetdir, 'dotnet.dll');
%% Create directories if needed
if (exist(outdir, 'dir') ~= 7)
mkdir(outdir);
end
if (exist(dnetdir, 'dir') ~= 7)
mkdir(dnetdir);
end
%% Build .NET Assembly
eval(['mcc -N -d ' dnetdir ' -W ''dotnet:dotnet,' ...
'dotnetclass,0.0,private'' -T link:lib ' mfile]);
I'm getting this error.
??? Error using ==> mcc
The output directory,
'C:\Users\H\Documents\Project\thesis\Source'
does not exist.
I'm pretty sure it's because of the space in the directory path "...\Source Code\...".
Because if I just use another path with no spaces it works perfectly fine.
Is there a way to make this work?
Thank you.
I think the actual problem occurs with your EVAL statement. You build a string to evaluate by concatenating strings like dnetdir and mfile, each of which will have a file path with a space in it. The resulting string you pass to EVAL will look like this:
mcc -N -d C:\Users\H\Documents\Source Code\MatlabFiles\dotnet -W ...
^--Look at that ugly space!
What you need to do is build your string so that there are apostrophes around these paths, like this:
eval(['mcc -N -d ''' dnetdir ''' -W ''dotnet:dotnet,' ...
'dotnetclass,0.0,private'' -T link:lib ''' mfile '''']);
Which will result in a string that looks like this:
mcc -N -d 'C:\Users\H\Documents\Source Code\MatlabFiles\dotnet' -W ...
And which will be evaluated properly now even with that nasty space in there.
I don't have any experience with mcc but some other functions may suffer from similar problems since most people are used to using the command mode (i.e. similar to the command prompt in DOS, Linux, Mac, ...). However, most functions are really functions such that you can use them in function mode and pass their arguments within parentheses.
You can also use mcc in function mode, as described in the help. That might look somewhat like:
mcc('-N', '-d', dnetdir, '-W', 'dotnet:dotnet,dotnetclass,0.0,private', '-T', 'link:lib', mfile);
That way you should not have to worry about escaping any character.
try changing the last line to:
eval(['mcc -N -d ''' dnetdir ''' -W ''dotnet:dotnet,' ...
'dotnetclass,0.0,private'' -T link:lib ' mfile]);
note the extra quotes around dnetdir
It seems to me that there are two ways to run Matlab in batch mode:
the first one:
unset DISPLAY
matlab > matlab.out 2>&1 << EOF
plot(1:10)
print file
exit
EOF
The second one uses option "-r MATLAB_command":
matlab -nojvm -nosplash -r MyCommand
Are these two equivalent?
What does "<< EOF" and the last "EOF" mean in the first method?
Thanks and regards!
The first method simply redirects the standard output > matlab.out and the standard error 2>&1 to the file matlab.out.
Then it uses the heredoc way of passing input to MATLAB (this is not specific to MATLAB, it is a method of passing multiple lines as input to command line programs in general).
The syntax is << followed by an unique identifier, then your text, finally the unique id to finish.
You can try this on the shell:
cat << END
some
text
multiple lines
END
The second method of using the -r option starts MATLAB and execute the statement passed immediately. It could be some commands or the name of a script or function found on the path.
It is equivalent to doing something like:
python -c "print 'hello world'"
Refer to this page for a list of the other start options.