Close matlab in shell script but keep the figure window.
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
My matlab script plots a scatter plot.I am running this matlab script within the shell script. My shell script has for loop. I want to close only matlab for every iteration of shell for loop but keep figure window on in order to plot scatter data for all iteration on same figure. Is there any way to enable figure window throughout the shell script run ?
matlab -nodesktop -r "matlabscript; {dont want to close figure window} ; exit"
0 Kommentare
Antworten (2)
Walter Roberson
am 27 Nov. 2015
No, not in the way you are proceeding. However, if you are using one of the Bourne shell derivatives, including ksh or bash, then you can open a pipe to a process and read and write to the process.
One route is to use named pipes; see http://www.linuxjournal.com/content/using-named-pipes-fifos-bash
With ksh itself (but not bash) you can use the little-known facility known as "co-process"; see the ksh command page for "|&" and the <&p and >&p and the "-p" option of print.
2 Kommentare
Aurik
am 7 Sep. 2023
There's two (potential) issues I see
In the second for loop, you should have P(j).element instead of P(i).element
You should also have an fclose(q) after the fourth line L = fscanf(q,'%d %d',[2 inf]);
I dont know anything about your files or plot so there may possibly be other issues
Aurik
am 7 Sep. 2023
Bearbeitet: Aurik
am 7 Sep. 2023
Unfortunately the only way I was able to solve this was by eliminating the "exit" portion of the command. In this case, the figure will not close, the command window will also remain open. In this case, you must close the command window manually (either clicking the 'X' or by typing 'exit'); doing so will also close the figure.
---
Another way I circumvent this issue is by saving the figure out to an image every time it is generated. This code must be included within the MATLAB script.
% Insert your figure here
fig = figure;
scatter(1:10, rand([1,10]))
% Name of the image file
image_filename = 'image.png';
% Full file path (with directory)
image_filepath = fullfile('path_to_output_folder', image_filename);
saveas(fig, image_filepath)
When running the same script multiple times, sometimes I generate a unique filename so that I dont always write over my previously-generated images.
% Unique image filename, using the date/time for uniqueness
image_filename = ['image', char(datetime('now', 'Format', 'yyyyMMdd_HHmmss')), '.png'];
0 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!