Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change DISPLAY variable from within Matlab

Tags:

unix

matlab

I'm running some code remotely on Matlab on Unix that generates many plots. I don't want hundreds of figures to pop up on my local system. (And I suspect that the windowing process slows down the execution of my code too.) I read that setting the DISPLAY environment variable to null restricts this behavior, and indeed,

$export DISPLAY=
$matlab14a -nodisplay -nosplash
>>X=1:10;
>>Y=X.^2;
>>plot(X,Y);

Immediately returns the cursor to the console and does not display the plot. However, then I want to be able to toggle the display back on. I can run

>>setenv('DISPLAY',':1102') %Previous (correct) value of $DISPLAY
>>getenv('DISPLAY')
ans = 
:1102
>>plot(X,Y);

However, the plot still does not appear. I believe that this occurs because my system routes the matlab instance through the qrsh scheduler and then another subshell. So when I change my DISPLAY variable, I believe that whichever shell is not accessing this variable. I don't know the exact details of this process.

My question is, how can I get Matlab to correctly display plots once I have changed the DISPLAY variable to the correct value? Alternately, are there any other solutions for toggling the display of all plots/figures?

like image 964
Micah Smith Avatar asked Aug 11 '14 20:08

Micah Smith


People also ask

How do you display a variable value in MATLAB?

disp( X ) displays the value of variable X without printing the variable name. Another way to display a variable is to type its name, which displays a leading “ X = ” before the value. If a variable contains an empty array, disp returns without displaying anything.

How do I change the value of a variable in MATLAB?

You can edit the value of a variable element by clicking the element and typing a new value. Press Enter or click another element to save the change.

How do you display words in MATLAB?

To display a text in MATLAB, we use 'disp function' which displays the text or value stored in a variable without actually printing the name of the variable.

What is a variable in MATLAB?

MATLAB Variable. After reading this MATLAB Variable topic, you will understand how to create and manipulate Variable, and you will understand how to assign and display variable data in MATLAB. In MATLAB, an assignment statement automatically generates variable. An assignment statement used for assigning a value to a variable.

What is an assignment statement in MATLAB?

In MATLAB, an assignment statement automatically generates variable. An assignment statement used for assigning a value to a variable. The assignment statement generally having the symbol = which is known as the assignment operator. x is variable. 10 is the value assigned to variable x.

How to print a variable value in matlb?

In MATLB, fprintf statement is used to print a variable data. x is variable. = is the assignment operator. fprintf (‘The x is %d ’,x) statement to display variable x value.

What is the maximum length of a variable name in MATLAB?

Variable name length limits up to 63 characters long. A variable name can be made with letters, digits, and the underscore character. Punctuation characters (e.g., period, comma, semicolon) are not allowed for defining variable names. MATLAB is case sensitive: it discriminates between uppercase and lowercase letters.


1 Answers

I think that running maltab with -nodisplay flag makes it ignore completely all figures and I do not think you can recover from that by changing the DISPLAY environment variable.

What you can do is setting the default 'visible' property to 'off'

set( 0, 'DefaultFigureVisible', 'off');

Before your code starts to run and only turn 'visible' to 'on' for the figures you really want to see. Or, resetting the default value to 'on' once you are done with the main computation part of your program.

set( 0, 'DefaultFigureVisible', 'on');

See here for more info about setting default values for properties.

like image 175
Shai Avatar answered Oct 25 '22 23:10

Shai