Skip to content

Commit

Permalink
added function for detecting no display to avoid maximum recursion de…
Browse files Browse the repository at this point in the history
…pth error
mim committed May 24, 2015
1 parent 5dc753c commit 562d435
Showing 2 changed files with 14 additions and 7 deletions.
8 changes: 8 additions & 0 deletions isNoDisplay.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function v = isNoDisplay()

% Return true if matlab was called with the -nodisplay option, false
% otherwise

% From http://www.mathworks.com/matlabcentral/newsreader/view_thread/136261
ss = get(0, 'Screensize');
v = all(ss(3:4) == [1 1]);
13 changes: 6 additions & 7 deletions subplots.m
Original file line number Diff line number Diff line change
@@ -12,6 +12,11 @@ function subplots(data, layout, names, formatFn)
if ~exist('names', 'var'), names = {}; end
if ~exist('formatFn', 'var') || isempty(formatFn), formatFn = @(r,c,i) []; end

if isNoDisplay()
% Don't bother...
return
end

if isstruct(data)
names = fieldnames(data);
data = struct2cell(data);
@@ -37,13 +42,7 @@ function subplots(data, layout, names, formatFn)
names = cellfun(@(x) num2str(x), num2cell(1:nPlots), 'UniformOutput', false);
end

try
clf
catch ex
% No display
return
end

clf
for i = 1:nPlots
subplot(nRows, nCols, i);
x = data{i};

0 comments on commit 562d435

Please sign in to comment.