Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
28 changes: 28 additions & 0 deletions +AMF/+utils/defineCustomColormap.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
function clist = define_custom_colormap(c_matrix,N)

if length(c_matrix) == 3
clist(1,:) = c_matrix{1}; %start color
clist(ceil(N/2),:) = c_matrix{2}; %middle color
clist(N,:) = c_matrix{3}; %end color

dc1 = clist(ceil(N/2),:) - clist(1,:);
for i1 = 2:ceil(N/2)-1
clist(i1,:) = clist(i1-1,:) + dc1/(N-1);
end

dc2 = clist(N,:) - clist(ceil(N/2),:);
for i2 = ceil(N/2)+1:N-1
clist(i2,:) = clist(i2-1,:) + dc2/(N-1);
end


elseif length(c_matrix) == 2
clist(1,:) = c_matrix{1}; %start color
clist(N,:) = c_matrix{2}; %end color

dc = clist(N,:)-clist(1,:);

for i = 2:N-1
clist(i,:) = clist(i-1,:) + dc/(N-1);
end
end
14 changes: 14 additions & 0 deletions +AMF/+utils/getHist.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function [N,C] = getHist(t,v,r,ny)

a = repmat(t,size(v,1),1);
b = reshape(v.',numel(v),1);

if numel(r) > 0
[N, C] = hist3([a,b],{t,[r(1) : (r(2)-r(1))/(ny-1) : r(2)]});
else
[N, C] = hist3([a,b],[numel(t) ny]);
end
N = log10(N);
N = N./max(max(N));

N(N==-inf) = 0;
6 changes: 6 additions & 0 deletions +AMF/+utils/mexify.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
function outputStr = mexify(inputStr)

outputStr = inputStr;

% parsers
outputStr = regexprep(outputStr, '([-+\w]+)\^([-+\w]+)', 'pow($1,$2)');
8 changes: 8 additions & 0 deletions +AMF/+utils/mexify2.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function outputStr = mexify2(inputStr, compName)

outputStr = inputStr;

% parsers
outputStr = regexprep(outputStr, '([-+\w]+)\^([-+\w]+)', 'pow($1,$2)');

outputStr = regexprep(outputStr, 'if\((.*),(.*),(.*)\)', sprintf('0;\nif ($1)\n\t%s = $2;\nelse\n\t%s = $3;\nend', compName, compName));
82 changes: 82 additions & 0 deletions +AMF/+utils/parfor_progress.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
function percent = parfor_progress(N)
%PARFOR_PROGRESS Progress monitor (progress bar) that works with parfor.
% PARFOR_PROGRESS works by creating a file called parfor_progress.txt in
% your working directory, and then keeping track of the parfor loop's
% progress within that file. This workaround is necessary because parfor
% workers cannot communicate with one another so there is no simple way
% to know which iterations have finished and which haven't.
%
% PARFOR_PROGRESS(N) initializes the progress monitor for a set of N
% upcoming calculations.
%
% PARFOR_PROGRESS updates the progress inside your parfor loop and
% displays an updated progress bar.
%
% PARFOR_PROGRESS(0) deletes parfor_progress.txt and finalizes progress
% bar.
%
% To suppress output from any of these functions, just ask for a return
% variable from the function calls, like PERCENT = PARFOR_PROGRESS which
% returns the percentage of completion.
%
% Example:
%
% N = 100;
% parfor_progress(N);
% parfor i=1:N
% pause(rand); % Replace with real code
% parfor_progress;
% end
% parfor_progress(0);
%
% See also PARFOR.

% By Jeremy Scheff - jdscheff@gmail.com - http://www.jeremyscheff.com/

% error(nargchk(0, 1, nargin, 'struct'));

if nargin < 1
N = -1;
end

percent = 0;
w = 50; % Width of progress bar

if N > 0
f = fopen('parfor_progress.txt', 'w');
if f<0
error('Do you have write permissions for %s?', pwd);
end
fprintf(f, '%d\n', N); % Save N at the top of progress.txt
fclose(f);

if nargout == 0
disp([' 0%[>', repmat(' ', 1, w), ']']);
end
elseif N == 0
delete('parfor_progress.txt');
percent = 100;

if nargout == 0
disp([repmat(char(8), 1, (w+9)), char(10), '100%[', repmat('=', 1, w+1), ']']);
end
else

if ~exist('parfor_progress.txt', 'file')
error('parfor_progress.txt not found. Run PARFOR_PROGRESS(N) before PARFOR_PROGRESS to initialize parfor_progress.txt.');
end

f = fopen('parfor_progress.txt', 'a');
fprintf(f, '1\n');
fclose(f);

f = fopen('parfor_progress.txt', 'r');
progress = fscanf(f, '%d');
fclose(f);
percent = (length(progress)-1)/progress(1)*100;

if nargout == 0
perc = sprintf('%3.0f%%', percent); % 4 characters wide, percentage
disp([repmat(char(8), 1, (w+9)), char(10), perc, '[', repmat('=', 1, round(percent*w/100)), '>', repmat(' ', 1, w - round(percent*w/100)), ']']);
end
end
82 changes: 82 additions & 0 deletions +AMF/+utils/parfor_progress2.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
function percent = parfor_progress2(N)
%PARFOR_PROGRESS Progress monitor (progress bar) that works with parfor.
% PARFOR_PROGRESS works by creating a file called parfor_progress.txt in
% your working directory, and then keeping track of the parfor loop's
% progress within that file. This workaround is necessary because parfor
% workers cannot communicate with one another so there is no simple way
% to know which iterations have finished and which haven't.
%
% PARFOR_PROGRESS(N) initializes the progress monitor for a set of N
% upcoming calculations.
%
% PARFOR_PROGRESS updates the progress inside your parfor loop and
% displays an updated progress bar.
%
% PARFOR_PROGRESS(0) deletes parfor_progress.txt and finalizes progress
% bar.
%
% To suppress output from any of these functions, just ask for a return
% variable from the function calls, like PERCENT = PARFOR_PROGRESS which
% returns the percentage of completion.
%
% Example:
%
% N = 100;
% parfor_progress(N);
% parfor i=1:N
% pause(rand); % Replace with real code
% parfor_progress;
% end
% parfor_progress(0);
%
% See also PARFOR.

% By Jeremy Scheff - jdscheff@gmail.com - http://www.jeremyscheff.com/

% error(nargchk(0, 1, nargin, 'struct'));

if nargin < 1
N = -1;
end

percent = 0;
w = 50; % Width of progress bar

if N > 0
f = fopen('parfor_progress.txt', 'w');
if f<0
error('Do you have write permissions for %s?', pwd);
end
fprintf(f, '%d\n', N); % Save N at the top of progress.txt
fclose(f);

if nargout == 0
disp([' 0%[>', repmat(' ', 1, w), ']']);
end
elseif N == 0
delete('parfor_progress.txt');
percent = 100;

if nargout == 0
disp([repmat(char(8), 1, (w+9)), char(10), '100%[', repmat('=', 1, w+1), ']']);
end
else

if ~exist('parfor_progress.txt', 'file')
error('parfor_progress.txt not found. Run PARFOR_PROGRESS(N) before PARFOR_PROGRESS to initialize parfor_progress.txt.');
end

% f = fopen('parfor_progress.txt', 'a');
% fprintf(f, '1\n');
% fclose(f);

f = fopen('parfor_progress.txt', 'r');
progress = fscanf(f, '%d');
fclose(f);
percent = (length(progress)-1)/progress(1)*100;

if nargout == 0
perc = sprintf('%3.0f%%', percent); % 4 characters wide, percentage
disp([perc, '[', repmat('=', 1, round(percent*w/100)), '>', repmat(' ', 1, w - round(percent*w/100)), ']']);
end
end
5 changes: 5 additions & 0 deletions +AMF/+utils/writeFile.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function writeFile(fn, content)

fid = fopen(fn, 'w');
fprintf(fid, content);
fclose(fid);
28 changes: 28 additions & 0 deletions +AMF/+visualisation/define_custom_colormap.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
function clist = define_custom_colormap(c_matrix,N)

if length(c_matrix) == 3
clist(1,:) = c_matrix{1}; %start color
clist(ceil(N/2),:) = c_matrix{2}; %middle color
clist(N,:) = c_matrix{3}; %end color

dc1 = clist(ceil(N/2),:) - clist(1,:);
for i1 = 2:ceil(N/2)-1
clist(i1,:) = clist(i1-1,:) + dc1/(N-1);
end

dc2 = clist(N,:) - clist(ceil(N/2),:);
for i2 = ceil(N/2)+1:N-1
clist(i2,:) = clist(i2-1,:) + dc2/(N-1);
end


elseif length(c_matrix) == 2
clist(1,:) = c_matrix{1}; %start color
clist(N,:) = c_matrix{2}; %end color

dc = clist(N,:)-clist(1,:);

for i = 2:N-1
clist(i,:) = clist(i-1,:) + dc/(N-1);
end
end
59 changes: 59 additions & 0 deletions +AMF/+visualisation/define_figure_details.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
function plotinfo = define_figure_details(varargin)

if ~isempty(varargin)
plotinfo = varargin{1};
else
plotinfo = struct();
end
% figure size
dx = 10;
dy = 50;
ss = get(0,'ScreenSize');
xmax = ss(3)-dx-10;
ymax = ss(4)-dy-80;
set(0,'DefaultFigurePosition',[dx dy xmax ymax]);


% font size
if ~isfield(plotinfo,'FS')
plotinfo.FS = 24; %40;
end

% line width of axes
if ~isfield(plotinfo,'LW_axes')
plotinfo.LW_axes = 2; %3;
end

% line width & marker size of (raw) data points
if ~isfield(plotinfo,'LW_data')
plotinfo.LW_data = 2;
end
if ~isfield(plotinfo,'MS_data')
plotinfo.MS_data = 14;
end

% line width of spline data
if ~isfield(plotinfo,'LW_spline')
plotinfo.LW_spline = 3;
end

% line width of model simulations / trajectories
if ~isfield(plotinfo,'LW_sim')
plotinfo.LW_sim = 4;
end


% text properties
set(0,'DefaultTextFontName','Myriad')
set(0,'DefaultTextFontSize',plotinfo.FS);
set(0,'DefaultTextInterpreter','tex');

% line and marker properties
set(0,'DefaultLineLineWidth',plotinfo.LW_data);
set(0,'DefaultLineMarkerSize',plotinfo.MS_data);

% axes properties
set(0,'DefaultAxesFontName','Myriad')
set(0,'DefaultAxesFontSize',plotinfo.FS);
set(0,'DefaultAxesLineWidth',plotinfo.LW_axes);
end
70 changes: 70 additions & 0 deletions +AMF/+visualisation/errorbar_tick.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
function errorbar_tick(h,w,xtype)
%ERRORBAR_TICK Adjust the width of errorbars
% ERRORBAR_TICK(H) adjust the width of error bars with handle H.
% Error bars width is given as a ratio of X axis length (1/80).
% ERRORBAR_TICK(H,W) adjust the width of error bars with handle H.
% The input W is given as a ratio of X axis length (1/W). The result
% is independent of the x-axis units. A ratio between 20 and 80 is usually fine.
% ERRORBAR_TICK(H,W,'UNITS') adjust the width of error bars with handle H.
% The input W is given in the units of the current x-axis.
%
% See also ERRORBAR
%

% Author: Arnaud Laurent
% Creation : Jan 29th 2009
% MATLAB version: R2007a
%
% Notes: This function was created from a post on the french forum :
% http://www.developpez.net/forums/f148/environnements-developpement/matlab/
% Author : Jerome Briot (Dut)
% http://www.mathworks.com/matlabcentral/newsreader/author/94805
% http://www.developpez.net/forums/u125006/dut/
% It was further modified by Arnaud Laurent and Jerome Briot.

% Check numbers of arguments
error(nargchk(1,3,nargin))

% Check for the use of V6 flag ( even if it is depreciated ;) )
flagtype = get(h,'type');

% Check number of arguments and provide missing values
if nargin==1
w = 80;
end

if nargin<3
xtype = 'ratio';
end

% Calculate width of error bars
if ~strcmpi(xtype,'units')
dx = diff(get(gca,'XLim')); % Retrieve x limits from current axis
w = dx/w; % Errorbar width
end

% Plot error bars
if strcmpi(flagtype,'hggroup') % ERRORBAR(...)

hh=get(h,'children'); % Retrieve info from errorbar plot
x = get(hh(2),'xdata'); % Get xdata from errorbar plot

x(4:9:end) = x(1:9:end)-w/2; % Change xdata with respect to ratio
x(7:9:end) = x(1:9:end)-w/2;
x(5:9:end) = x(1:9:end)+w/2;
x(8:9:end) = x(1:9:end)+w/2;

set(hh(2),'xdata',x(:)) % Change error bars on the figure

else % ERRORBAR('V6',...)

x = get(h(1),'xdata'); % Get xdata from errorbar plot

x(4:9:end) = x(1:9:end)-w/2; % Change xdata with respect to the chosen ratio
x(7:9:end) = x(1:9:end)-w/2;
x(5:9:end) = x(1:9:end)+w/2;
x(8:9:end) = x(1:9:end)+w/2;

set(h(1),'xdata',x(:)) % Change error bars on the figure

end
Loading