Gnuplot incremental filename using macro - macros

Hell,
I need to plot points out of my c++ application.
So I simply save my points to a points.txt
and then run system("gnuplot 'plotmakro'");
which contains:
set output 'plot.png' set terminal png
set grid set multiplot
plot pointsa.txt' ', 'pointb.txt'
Is there a solution so that I get plot2.png, plot3.png when running the makro again?

As far as I understand your problem two possible solutions come to my mind:
sed the output of your gnuplot script to another location before running gnuplot with the newly created script or
output the png to some arbitrary file like tmp_plot.png and change the file name after gnuplot is done to your liking.
However, with both suggestions I somehow feel that there is a nicer and cleaner solution to your problem. Maybe you want to think about your interface between your application an gnuplot...

Related

export image fails using cmaple.exe but OK using maple.exe

Is there a difference from running the same exact Maple commands to export a plot, when run from GUI interface, using worksheet, vs. from plain text .mpl file using command line Maple?
The following code runs OK from the GUI worksheet, but gives error
Error, invalid FONT specification when run from cmaple.exe.
This is on windows 10.
#file T1.mpl
currentdir("C:/TMP"); #or any other folder of your choice
plotsetup(default); #start from default
#the following commnad below export a plot to a file
plotsetup(ps, plotoutput="t.ps",
plotoptions=`color,noborder,portrait,height=250`);
p0:=DEtools:-DEplot( diff(y(x),x)=x, y(x), x=-2..2, y=-2..2,
'color' = "#00aaff",
'arrows'='medium',
'labels'=["",""],
'thickness'=1
):
#this will send the plot to a file.
print(plots:-display([p0],'view'=[-2..2.4,-2..2.5],
axis=[tickmarks=['color'='red']],
font=["Times",bold,8]
)
);
#ERROR SHOWS HERE
plotsetup(default); #rest back to default
The print command above, does not actually display anything, even on the GUI, since it was redirected to go to a file.
The above code works with no problem in the GUI interface, and the plots is exported OK to t.ps file.
I am trying to run the large Maple code I have from .mpl using command line Maple, hoping it will be faster than in worksheet, but the above problem is making it not possible.
First time trying cmaple.exe
Command I used is
"C:\Program Files\Maple 2018\bin.X86_64_WINDOWS\cmaple.exe" T1.mpl
May be I need an option to add to the command above?
This is using Maple 2018.1
The plot export driver in the Commandline Interface (CLI, aka TTY) does not know about the more modern calling sequences allowed for the various font related plotting options.
In modern Maple the font options can be specified using strings instead of names. That helps users avoid issues with assigning to alternative all-caps name forms, not all of which are protected names.
Unfortunately, it seems as if the CLI plot export driver does not know about the newer string forms. I will submit a bug report.
But you can still use the older, all-caps, name form.
Replace,
font=["Times",bold,8]
by,
font=[TIMES,BOLD,8]
Back when I was quite current with Maple, the answer to this question would have been: the GUI and the TTY version use different plot drivers. And the TTY plot drivers are not as well maintained as the ones for the GUI, and so more recent features do not always work for them.
I am guessing that this is still the case, and that the TTY plot driver doesn't know about fonts.

Exporting a figure

I came across this program for exporting a figure. I just want to ask, what should I pass to the program if I want to export a figure of mine to some image (i.e; .jpg), as I couldn't figure out what to pass as a parameter.
Thanks.
The built-in command print is used to export a figure to an image. Like so:
plot(rand(4))
print('-djpeg', 'myplot.jpg')
patrik's suggestion probably refers to this ME file. (Which is great, by the way)
A native MATLAB solution would be
saveas(<handle of the figure>,<file path with .jpg at the end>)
This is what I have used for a long time and it works (e.g., saveas(h,'/figures/automatic/myfig.jpg')); but it is very possible that print or something else is better suited for whatever reason.

is there a way to update workspace or variable editor values during running script without a break point

I would like to update variable editor at a predefined interval during a running script without having to use a break. Is this possible? I have a sim that runs for hours, I would like to be able to come back every hour and grab some values off a matrix in variable editor to play with in excel without interrupting running script. Any ideas would be greatly appreciated.
I think using assignin to copy your matrix to the base workspace should do exactly what you want. You'd need to manually reopen the variable in the editor to reflect the new data if it's changed.
If you wanted to get fancier, I imagine you could script evalin and openvar to do it for you, but I no longer have real Matlab to test with and Octave's fledgling GUI isn't there yet.

Editing a Text File from Matlab

I'm still getting used to Matlab, and not sure if this is possible using Matlab or not, but it's just something that popped into my head that I thought could be interesting.
Is there any way to edit the contents of a text file in Matlab?
Moreover, is there any way to edit specific parts of the text file without altering the rest?
To elaborate, let's say I had a text file that was several lines long. For instance:
This is a hypothetical text file.
The cat chased a mouse.
The mouse ran into a hole.
The cat tried to paw at the mouse.
The mouse waited in the hole until the cat got bored.
The mouse came back out when the cat left.
Is there any way to use Matlab to exclusively edit, say, line 6 and change it from "The mouse waited in the hole until the cat got bored" to "The mouse fell asleep and the cat got bored", without having to change the rest of the file?
I know of several methods to read and display contents of text files using Matlab, but I'm not sure if there's any way to actually edit the text files in Matlab.
Thanks!
As far as I know, you will always have to read the file line by line (for instance into a cell-array) and edit it as you need. After that, you write a new file or overwrite the old one.
Of course, you can encapsulate this procedure and then call you own function like
manipulateFile(lineNumber, newLineText)
Some commands that may come in handy are fopen, fscanf, textread, fprintf, and fclose.

Write a figure to a file automatically in MATLAB

Does anyone know if it's possible to automatically write a figure out to a .eps file in MATLAB?
I'm running a script that produces a large number of graphs, and it'd be nice if I didn't have to manually save each one!
print function does that:
Print figure or save to specific file format...
print(filename,formattype) saves the current figure to a file using the specified file format, such as print('BarPlot','-dpng'). If the file name does not include an extension, then print appends the appropriate one.
print(filename,formattype,formatoptions) specifies additional options that are available for some formats.
print prints the current figure to the default printer...
print or saveas will do the trick.
saveas(fig_handle, 'filename','eps')
print('-deps',fig_handle)
print -deps 1
If you want to specify the output file name, you're better off using saveas.
This was answered in this other question, using the PRINT command. Although that question dealt with making .tiff images, it should be straightforward to modify the code given in those answers to write a .eps.
Suppose, you are generating N numbers of figures in a loop, then you should try the command line:
saveas(gca,sprintf('Figure%02d.pdf',N )); it produces N figures Figure1.pdf - FigureN.pdf
saveas(gca,sprintf('Figure%02d.eps',N )); it produces N figures Figure1.eps - FigureN.eps
in place of gca one can use gcf also. First command line is a better solution.
Hope this will solve your issue.