Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanLRH committed Nov 18, 2014
0 parents commit 8ea1e3e
Show file tree
Hide file tree
Showing 13 changed files with 589 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Apps/*
read_hdf5.m
structree.m
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Matlab files

Theese files resides in my MATALB directory, and is avaiable on my Matlab path.

Most of them are by no means bulletproof, and bugs will most likely occur, but they can be useful nonetheless.
35 changes: 35 additions & 0 deletions anvar.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
%% mianx: returns min and max of reshaped multidimmensional matrix
function anvar(in, varargin)
if not(isnumeric(in))
disp('anvar only handles numeric data')
else
reshapedData = reshape(in, [1 numel(in)]);
sizeCell = regexpi(mat2str(size(in)), '\s+', 'split');
sizeString = '';
for ii = 1:length(sizeCell)-1
sizeString = [sizeString sizeCell{ii} ' '];
end
sizeString = [sizeString sizeCell{end}];
sizeString = strrep(sizeString, '[', '');
sizeString = strrep(sizeString, ']', '');
disp(sprintf('\nmin max minabs maxabs mean std\n%.3e %.3e %.3e %.3e %.3e %.3e',...
min(reshapedData), max(reshapedData), min(abs(reshapedData)), max(abs(reshapedData)), mean(reshapedData), std(reshapedData)));
disp(sprintf('\n%d elements in shape: \n%s\n\n\n', numel(reshapedData), sizeString));
if numel(in) > 1 && isempty(varargin)
figure();
if ndims(in) == 2
[r c] = size(in);
if r > c
plot(in)
else
plot(in')
end
else
plot(reshapedData)
end
grid on
box off
set(gcf, 'name', 'anvar plot');
end
end
end
28 changes: 28 additions & 0 deletions channelPlot.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
function varargout = channelPlot(rgb, varargin)
names = {'rgb', 'hsv', 'lab', 'sqrt(xyz)', 'ntsc', 'ycbcr'};
imData{1} = rgb;
imData{2} = rgb2hsv(rgb);
imData{3} = rgb2lab(rgb);
imData{4} = sqrt(rgb2xyz(rgb));
imData{5} = rgb2ntsc(rgb);
imData{6} = rgb2ycbcr(rgb);

if nargin > 1
imData = cellfun(varargin{1}, imData, 'UniformOutput', false);
names = {'f(rgb)', 'f(hsv)', 'f(lab)', 'f(sqrt(xyz))', 'f(ntsc)', 'f(ycbcr)'};
end

for ii = length(imData):-1:1
data = imData{ii};
ch = size(data, 3);
for jj = 1:ch
figure;
imsc(data(:, :, jj));
title(sprintf('%s(%d)', names{ii}, jj))
end
end




end
256 changes: 256 additions & 0 deletions ddoc.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,256 @@
%% ddoc: open matlab documentation page
function ddoc(func)
if exist(func)
web(['http://www.mathworks.se/help/matlab/ref/' strtrim(func) '.html'], '-browser')
else
web(['http://www.mathworks.se/help/search/doccenter/en/R2013b?qdoc=' strtrim(func)], '-browser')
end
end




% function doc(varargin)
% % DOC Reference page in Help browser.
% %
% % DOC opens the Help browser, if it is not already running, and
% % otherwise brings the Help browser to the top.
% %
% % DOC FUNCTIONNAME displays the reference page for FUNCTIONNAME in
% % the Help browser. FUNCTIONNAME can be a function or block in an
% % installed MathWorks product.
% %
% % DOC METHODNAME displays the reference page for the method
% % METHODNAME. You may need to run DOC CLASSNAME and use links on the
% % CLASSNAME reference page to view the METHODNAME reference page.
% %
% % DOC CLASSNAME displays the reference page for the class CLASSNAME.
% % You may need to qualify CLASSNAME by including its package: DOC
% % PACKAGENAME.CLASSNAME.
% %
% % DOC CLASSNAME.METHODNAME displays the reference page for the method
% % METHODNAME in the class CLASSNAME. You may need to qualify
% % CLASSNAME by including its package: DOC PACKAGENAME.CLASSNAME.
% %
% % DOC FOLDERNAME/FUNCTIONNAME displays the reference page for the
% % FUNCTIONNAME that exists in FOLDERNAME. Use this syntax to display the
% % reference page for an overloaded function.
% %
% % DOC USERCREATEDCLASSNAME displays the help comments from the
% % user-created class definition file, UserCreatedClassName.m, in an
% % HTML format in the Help browser. UserCreatedClassName.m must have a
% % help comment following the classdef UserCreatedClassName statement
% % or following the constructor method for UserCreatedClassName. To
% % directly view the help for any method, property, or event of
% % UserCreatedClassName, use dot notation, as in DOC
% % USERCREATEDCLASSNAME.METHODNAME.
% %
% % Examples:
% % doc abs
% % doc fixedpoint/abs % ABS function in the Fixed-Point Designer Product
% % doc handle.findobj % FINDOBJ method in the HANDLE class
% % doc handle % HANDLE class
% % doc containers.Map % Map class in the containers method
% % doc sads % User-created class, sads
% % doc sads.steer % steer method in the user-created class, sads

% % Copyright 1984-2013 The MathWorks, Inc.
% % $Revision: 1.1.6.38 $ $Date: 2013/05/13 22:41:05 $

% % Make sure that we can support the doc command on this platform.
% if ~usejava('mwt')
% error(message('MATLAB:doc:UnsupportedPlatform', upper(mfilename)));
% end

% % Examine the inputs to see what options are selected.
% [showClassicDoc, topic] = examineInputs(varargin{:});

% % Check this before checking docroot, the -classic option is used to show doc not under docroot.
% if showClassicDoc
% com.mathworks.mlservices.MLHelpServices.invokeClassicHelpBrowser();
% return;
% end

% % Make sure docroot is valid.
% if ~helpUtils.isDocInstalled
% % If m-file help is available for this topic, call helpwin.
% if ~isempty(topic)
% if showHelpwin(topic)
% return;
% end
% end

% % Otherwise show the appropriate error page.
% htmlFile = fullfile(matlabroot,'toolbox','local','helperr.html');

% if exist(htmlFile, 'file') ~= 2
% error(message('MATLAB:doc:HelpErrorPageNotFound', htmlFile));
% end
% displayFile(htmlFile);
% return
% end

% % Case no topic specified.
% if isempty(topic)
% % Just open the help browser and display the default startup page.
% com.mathworks.mlservices.MLHelpServices.invoke();
% return
% end

% if strncmpi(topic, 'mupad/', 6)
% if ~mupaddoc(topic)
% showNoReferencePageFound;
% end
% return;
% end

% [isOperator, docTopic] = helpUtils.isOperator(topic);
% hasLocalFunction = any(topic==filemarker);
% isMethodOrProp = false;

% if ~isOperator && ~hasLocalFunction
% [docTopic, isMethodOrProp] = getClassInformation(topic);
% end

% if isempty(docTopic)
% docTopic = topic;
% end

% if ~showTopic(docTopic, isMethodOrProp)
% if hasLocalFunction || ~showWhichTopic(topic,docTopic)
% if ~showHelpwin(topic)
% docsearch(topic);
% end
% end
% end
% end

% %------------------------------------------
% % Helper functions
% function success = showWhichTopic(topic,docTopic)
% success = false;
% whichTopic = helpUtils.safeWhich(topic);
% % Don't call getClassInformation with the same argument as before.
% if ~isempty(whichTopic) && ~isequal(whichTopic,topic)
% [whichDocTopic, isMethodOrProp] = getClassInformation(whichTopic);
% % Don't call showTopic with the same argument as before.
% if ~isempty(whichDocTopic) && ~isequal(whichDocTopic,docTopic)
% success = showTopic(whichDocTopic, isMethodOrProp);
% end
% end
% end

% function [topic, isElement] = getClassInformation(topic)
% isElement = false;
% classInfo = helpUtils.splitClassInformation(topic, '', false);
% topic = [];
% if ~isempty(classInfo)
% isElement = classInfo.isMethod || classInfo.isSimpleElement;
% topic = classInfo.getDocTopic(false);
% end
% end

% function success = showTopic(topic, isMethodOrProp)
% topicParts = getTopicParts(topic);
% if isempty(topicParts)
% success = false;
% elseif ~isempty(topicParts.dir)
% % Case topic path specified, e.g., symbolic/diag.
% fullTopic = [topicParts.dir '/' topicParts.name];
% success = showReferencePage(fullTopic, isMethodOrProp);
% if ~success
% fullTopic = [topicParts.dir '.' topicParts.name];
% success = showReferencePage(fullTopic, isMethodOrProp);
% end
% else
% % Case toolbox path not specified.
% % Check for product page first. Otherwise,
% % search for all instances of this topic in the help hierarchy.
% % Display the first instance found and list the others
% % in the MATLAB command window.

% % Show the product page if that's what they're asking for...
% success = showProductPage(topicParts.name);
% if ~success
% % Show the reference page for the topic.
% success = showReferencePage(topicParts.name, isMethodOrProp);
% end
% end
% end

% % Helper function that splits up the topic into a topic directory, and a
% % topic name.
% function parts = getTopicParts(topic)
% parts = regexp(topic,'^(?<dir>[^\\/]*(?=[\\/]\w))?[\\/]?(?<name>(\W+|[^\\/]+))[\\/]?$','names');
% if isempty(parts)
% [path, name] = fileparts(topic);
% topic = helpUtils.getDocTopic(path, name, false);
% if ~isempty(topic)
% parts = regexp(topic,'^(?<dir>[^\\/]*(?=[\\/]\w))?[\\/]?(?<name>(\W+|[^\\/]+))[\\/]?$','names');
% end
% end
% if ~isempty(parts)
% parts.name = lower(parts.name);
% parts.name = regexprep(parts.name,'[\s-\(\)]|\.m$','');
% end
% end

% % Helper function that shows the reference page, displaying any overloaded
% % functions or blocks in the command window.
% function success = showReferencePage(topic, isMethodOrProp)
% success = com.mathworks.mlservices.MLHelpServices.showReferencePage(topic, isMethodOrProp);
% end

% % Helper function used to display the product page, used when the topic
% % is the short name of a product.
% function success = showProductPage(topic)
% success = com.mathworks.mlservices.MLHelpServices.showProductPage(topic);
% end

% % Helper function used to display the error page when no reference page
% % was found for the topic.
% function showNoReferencePageFound(topic)
% noFuncPage = helpUtils.underDocroot('nofunc.html');
% if ~isempty(noFuncPage)
% displayFile(noFuncPage);
% else
% error(message('MATLAB:doc:InvalidTopic', topic));
% end
% end

% % Helper function used to show the topic help using helpwin.
% function foundTopic = showHelpwin(topic)
% % turn off the warning message about helpwin being removed in a future
% % release
% s = warning('off', 'MATLAB:helpwin:FunctionToBeRemoved');

% foundTopic = helpwin(topic, '', '', '-doc');

% % turn the warning message back on if it was on to begin with
% warning(s.state, 'MATLAB:helpwin:FunctionToBeRemoved');
% end

% %------------------------------------------
% % Helper function that displays the HTML file in the appropriate browser.
% function displayFile(htmlFile)
% % Display the file inside the help browser.
% web(htmlFile, '-helpbrowser');
% end

% %--------------------------------------------------------------------------
% function [showClassicDoc, topic] = examineInputs(varargin)
% showClassicDoc = 0;
% topic = [];

% for i = 1:length(varargin)
% argName = strtrim(varargin{i});

% if strcmp(argName, '-classic')
% showClassicDoc = 1;
% else
% % assume this is the location.
% topic = argName;
% end
% end

% end
30 changes: 30 additions & 0 deletions getFields.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
%% getFields: Get fields matching input from struct.
%
% inStruct: Struct from which fields is to be extracted.
% inString: String with the field text. A '$' is used as
% a placeholder for the elements in 'specifier'.
% specifier: Vector with values to replace the '$' in 'inString'.
%
% RETURNS: Cell-array or Matrix (if all output is numeric).
%
function [out] = getFields(inStruct, inString, specifier)
out = cell(1, length(specifier));
isDouble = true;
for ii = 1:length(specifier)
field = strrep( strtrim(inString), '$', num2str(specifier(ii)) );
try
out{ii} = inStruct.(field);
catch
try
out{ii} = inStruct.(['MARS_' field]);
warning(['No field named, ' field ', trying to prepend string ''MARS_''!'])
catch
error(['No field in struct named ''' field ''' or ''MARS_' field '.']);
end
isDouble = isDouble && isa(out{ii}, 'double');
end
end
if isDouble
out = cell2mat(out);
end
end
19 changes: 19 additions & 0 deletions imsc.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function varargout = imsc(in, varargin)
h = imagesc(in);
colormap gray;
axis image tight off
for ii = 1:length(varargin)
if strcmpi(varargin{ii}, 'colormap')
colormap(varargin{ii+1});
elseif strcmpi(varargin{ii}, 'title')
title(varargin{ii+1});
elseif strcmpi(varargin{ii}, 'axis')
eval(['axis ' varargin{ii+1}]);
elseif strcmpi(varargin{ii}, 'colorbar')
colorbar;
end
end
if nargout == 1
varargout{1} = h;
end
end
4 changes: 4 additions & 0 deletions mmax.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
%% mmax: Apply max until only one number is returned.
function [maxVal] = mmax(inMat)
maxVal = max(inMat(:));
end
4 changes: 4 additions & 0 deletions mmin.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
%% mmin: Apply min until only one number is returned.
function [minVal] = mmin(inMat)
minVal = min(inMat(:));
end
1 change: 1 addition & 0 deletions nicecolor.m
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function cout = nicecolor(c);% cvector = nicecolor('r' | 'b' | etc. | 'R' | 'B' | etc. | 'yr' | 'brW' | etc.);% cvector = nicecolor('q1' ... 'q9');% cvector = nicecolor(same cvector)% clist = nicecolor(cell array of the above);%% NICECOLOR(a letter) returns the numbers for a standard Matlab color ('r','k',% etc.) or nicer versions of the same ('R','B',etc.). Blends are allowable too:% nicecolor('Bkr') is the element-by-element average of 'B' and 'k' and 'r'.% NICECOLOR('q' followed by a number) is a shade of gray: 'q7' is [.7 .7 .7].% NICECOLOR('q') = NICECOLOR('q5').% if a 3-element color vector is passed to NICECOLOR, it passes out the other% end unchanged.%% neil banas, feb 2002% ([email protected])% % options that include r, g, b, c, m, y, k, w, R, G, B, C, M, Y, K, W%-------------------cnames = 'rgbcmykwRGBCMYKW';colors = [1 0 0; % r0 1 0; % g0 0 1; % b0 1 1; % c1 0 1; % m1 1 0; % y0 0 0; % k1 1 1; % w1 .4 .4; % R: salmony0 .7 0; % G: a bit darker0 .4 1; % B: lighter: prints like 'b' appears on screen.2 1 1; % C: a bit darker.8 0 .6; % M: purple.9 .8 0; % Y: a bit darker0 0 0; % K1 1 1];% W%--------------------cc={};if ~iscell(c) for r = 1:size(c,1), cc = {cc{:} c(r,:)}; end else cc = c;endfor r = 1:length(cc) if ischar(cc{r}) cout(r,:) = colorblend(cc{r},colors,cnames); else cout(r,:) = cc{r}; endend%--------------------function cout0 = colorblend(c0,colors,cnames);cl = [];i = 1;while i <= length(c0) doublelength = 0; if c0(i)=='q' & i~=length(c0) doublelength = (c0(i+1) >= '0' & c0(i+1) <= '9'); end if doublelength cl = [cl; singlecolor(c0(i:i+1),colors,cnames)]; i = i + 2; else cl = [cl; singlecolor(c0(i),colors,cnames)]; i = i + 1; endendif size(cl,1) > 1 cout0 = mean(cl);else cout0 = cl;end%--------------------function cout1 = singlecolor(c1,colors,cnames);if c1(1)=='q' if length(c1)==1 cout1 = [.5 .5 .5]; else cout1 = str2num(c1(2))/10 .* [1 1 1]; endelseif length(c1) > 1 error(['nicecolor.m: bad color name (''' c1 ''')']);else j = find(cnames==c1); if isempty(j), error(['nicecolor.m: bad color name (''' c1 ''')']); end cout1 = colors(find(cnames==c1),:);end
Expand Down
Loading

0 comments on commit 8ea1e3e

Please sign in to comment.