69 pos = regexp(txt,sprintf(
" \n[ ]*\n "));
72 short = txt(1:pos(1)-1);
75 pos = strfind(txt,
char(10));
77 short = txt(1:pos(1)-1);
80 short = strtrim(
short);
96 static function [doublebmin , doublebmax ] =
getBoundingBox(
double vectors) {
97 bmin = min(vectors,[],2);
98 bmax = max(vectors,[],2);
116 if ~isa(ranges,
" cell ")
121 r =
cell(1,length(varargin)+1);
123 [r[2:end]] = varargin[:];
129 [matrices[1:n]] = ndgrid(ranges[:]);
131 comb = zeros(n,numel(matrices[1]));
134 if isempty(matrices[idx])
139 comb(idx,:) = matrices[idx](:);
160 if ~isstruct(source) || ~isstruct(target)
161 error(
" Both source and target arguments must be structs. ");
164 names = fieldnames(source);
165 for idx = 1:length(names)
167 if isstruct(source.(names[idx]))
169 if isempty(target.(names[idx]))
170 target.(names[idx]) =
struct;
175 target.(names[idx]) = source.(names[idx]);
198 str = sprintf(sprintf(
" %%.%de ",digits),value);
199 str = sprintf(
" %s ",str(1:digits+2));
200 expo = floor(log10(value));
202 str = sprintf(
" %s\\times10^{%d} ",str,expo);
204 str = sprintf(
" $%s$ ",str);
217 if isa(data,
" cell ")
220 fun = @(arg)sprintf(format,arg);
223 for idx = 2:length(data)
224 str = [str glue fun(data[idx])];
226 elseif isnumeric(data)
229 str = sprintf([format glue],data(1:end-1));
232 str = [str sprintf(format,data(end))];
234 error(
" Can only pass cell arrays of strings or a vector with sprintf format pattern ");
261 if size(A,1) ~= size(b,1)
262 error(
" Invalid arguments. ");
264 idx = zeros(1,size(b,2));
266 tmp = strfind(reshape(A,1,[]),b(:,n)^
t);
269 tmp(mod(tmp,size(b,1)) ~= 1) = [];
271 idx(n) = (tmp(1)+size(b,1)-1)/size(b,1);
299 fprintf(
" Utils/preparePlainPlot: Number of graphs for plot > 1000, taking graphs with distinct y(T) values.\n ");
300 [v,idx] = unique(y(:,end));
301 [v,idxm] = unique(y(:,round(size(y,2)/2)));
302 y = y(
union(idx,idxm),:);
305 fprintf(
" Utils/preparePlainPlot: Number of graphs for plot still > 4000, taking 4000 graphs.\n ");
306 y = y(round(1:sy/4000:sy),:);
326 if any(~ishandle(fig))
327 error(
" Invalid figure handle. ");
331 JPEGQuality =
" 95 ";
332 exts = [
" fig ",
" pdf ",
" eps ",
" jpg ",
" png ",
" tif "];
333 extd = [
" MatLab Figure ",
" PDF Files ",
" Extended PostScript ",
" JPEG Image ",...
334 " Portable Network Graphic ",
" TIFF Image "];
341 choices =
cell(length(exts),2);
342 for i = 1:size(choices,1)
343 choices[i,1] = [
" *. " exts[i]];
344 choices[i,2] = [extd[i]
" (*. " exts[i]
" ) "];
346 [filename, pathname, extidx] = uiputfile(choices,
" Save figure as ", ...
348 if ~isequal(filename, 0)
349 file = [pathname filename];
353 file = [filename
" . " exts[extidx]];
356 extidx = find(strcmp(ext,exts),1);
358 warning(
" KerMor:Utils:invalidExtension ",
" Invalid extension: %s, using eps ",ext);
361 file = [filename
" . " exts[extidx]];
367 if ~isempty(d) && exist(d,
" file ") ~= 7
386 saveas(fig, file,
" fig ");
388 args = [file, [
" - " exts[extidx]],[
" -r " ExportDPI]];
389 if any(extidx == [2 3])
392 args[end+1] =
" -transparent ";
395 args[end+1] = [
" -q " JPEGQuality];
399 args[end+1] =
" -transparent ";
411 c =
get(fig,
" Color ");
412 set(fig,
" Color ",
" white ");
416 set(fig,
" Color ",c);
421 fprintf(2,
" No file specified. Aborting\n ");
439 fig = figure(
" Visible ",
" off ",
" MenuBar ",
" none ",
" ToolBar ",
" none ");
467 fu =
get(f,
" Units ");
468 au =
get(a,
" Units ");
470 set(f,
" Units ",
" pixels ");
471 set(a,
" Units ",
" pixels ");
472 fpos =
get(f,
" Position ");
473 apos =
get(a,
" Position ");
474 ati =
get(a,
" TightInset ");
475 set(f,
" ActivePositionProperty ",
" Position ");
476 set(a,
" ActivePositionProperty ",
" Position ");
477 set(f,
" Position ",[fpos(1:2) apos(3:4)+ati(1:2)+ati(3:4)]);
478 set(a,
" Position ",[ati(1:2) apos(3:4)]);
520 r = RandStream(
" mt19937ar ",
" Seed ",seed);
521 farend = r.rand(dim,1)-.5;
522 farend = farend * length/norm(farend);
523 x = r.rand(dim,num)-.5;
524 x = bsxfun(@times, x, length*spread./
Norm.
L2(x));
525 x = x + bsxfun(@times, farend, r.rand(1,num));
553 L = chol(G,
" lower ");
564 opts.p= 20+ceil(.1*log(dim)*(dim^.35));
566 fprintf(
" Starting log norm computation for %d-dimensional matrix (eigs:maxit=%d, p=%d)\n ",...
567 dim,opts.maxit,opts.p);
570 [v, ln] = eigs(hlp,1,
" la ",opts);
572 if ~isempty(s) && strcmp(
id,
" MATLAB:eigs:NoEigsConverged ")
573 fprintf(
" Single eigenvalue not converged with p=%d. Re-trying with p=%d...\n ",...
576 [v, ln] = eigs(hlp,1,
" la ",opts);
579 opts.p= 20+ceil(.1*log(dim)*(dim^.35));
580 [v, ln] = eigs(hlp,1,-ln,opts);
582 if ~isempty(s) && strcmp(
id,
" MATLAB:eigs:NoEigsConverged ")
583 fprintf(
" Single (shifted by %g) eigenvalue not converged with p=%d. Re-trying with p=%d...\n ",...
584 -ln,opts.p,opts.p*2);
586 [v, ln] = eigs(hlp,1,
" la ",opts);
594 [ln, idx] = max(diag(d));
631 rs = RandStream(
" mt19937ar ",
" Seed ",0);
634 i = rs.randi(n,total,1);
635 j = rs.randi(m,total,1);
636 s = rs.rand(total,1);
637 S = sparse(i,j,s,n,m);
660 f =
get(0,
" CurrentFigure ");
669 static function folder =
getDir(caption,initial_path) {
670 if all(
get(0,
" Screensize ") == 1)
672 caption =
" Please specify a directory ";
674 folder = input([caption
" : "],
" s ");
682 folder = uigetdir(initial_path, caption);
702 if ~isempty(dir) && exist(dir,
" dir ") ~= 7
707 me = MException(
" Utils:ensureDir ",
" Could not create directory '%s' ",dir);
733 pfn = fieldnames(localp);
735 setpref(to,pfn[
k],localp.(pfn[k]));
749 format_string =
" %g ";
751 entries = cellfun(@(v)sprintf(format_string,v),num2cell(values),
" UniformOutput ",
false);
761 dim = round(rand*30);
766 res = res &
all(
Norm.
L2(x) <= length*(1+spread));
795 b(:,end+1) = rand(40,1);
799 a(:,end+1:end+2) = a(:,[idx(1) idx(5)]);
static function tag = getPrefTag()
Returns the tag used to store the KerMor preferences and settings.
Collection of generally useful functions.
function MD5 = CalcMD5(Data, InClass, OutClass)
128 bit MD5 checksum: file, string, byte stream [MEX] This function calculates a 128 bit checksum for...
static function closeAllFigures()
static function comb = createCombinations(ranges, varargin)
Creates the cartesian product of the vectors passed as a matrix containing elements of each vector pe...
static function idx = findVecInMatrix(A, b)
Finds column vectors inside a matrix.
A MatLab cell array or matrix.
static function res = test_Tube()
function [ im , alpha ] = export_fig(varargin)
Make sure the figure is rendered correctly now so that properties like axes limits are up-to-date...
static function copyPrefGroup(char from,char to)
Copies the preferences from one group to another.
Matlab's base handle class (documentation generation substitute)
A variable number of input arguments.
static function entries = getLegendFromVector(values, format_string)
static function saveFigure(fig, filename, ext)
Opens a matlab save dialog and saves the given figure to the file selected.
static function [ matrix< double > x , colvec< double > farend ] = getTube(integer dim,integer num,double length,double spread,integer seed)
Computes num random vectors inside a tube of length length inside a dim dimensional space...
static function h = getHash(vec)
Returns a hash code for the given vector.
static function folder = getDir(caption, initial_path)
Prompts the user to select a directory.
static function logical success = ensureDir(char dir)
Ensures that a directory exists.
static function char str = implode(char|rowvec data,char glue,char format)
Implodes the elements of data using glue.
static function rowvec< double > n = L2(matrix< double > x)
Returns the discrete norm for each column vector in x.
Global configuration class for all KerMor run-time settings.
static function [ double ln , colvec< double > v ] = logNorm(matrix< double > A,matrix< double > G,colvec< double > v0)
Computes the logarithmic norm of a matrix , optionally using a positive definite symmetric matrix in...
static function struct target = copyStructFields(struct source,struct target)
Recursively copies struct fields from one struct to another.
static function KerMor theinstance = App()
The singleton KerMor instance.
Norm: Static class for commonly used norms on sets of vectors.
static function res = test_findVec()
Tests the findVecInMatrix function.
static function removeMargin(f)
Requires the axes and figure units to be the same.
static function S = sprand(integer n,integer m,double dens,RandStream rs)
Creates a random sparse matrix with given density (approximately).
static function char short = getHelpShort(char txt)
Extracts the help short subtext from a given text.
static function str = getLatexStr(value, digits)
static function saveAxes(handle ax, varargin)
Convenience function. Allows to save a custom axes instead of a whole figure which allows to drop any...
static function res = test_createCombinations()
Tests the createCombinations function.
static function y = preparePlainPlot(y)
Memory-saving plotting for plain result plots.
static function [ double bmin , double bmax ] = getBoundingBox(double vectors)
Gets the bounding box for a matrix containing column vectors.