general¶
-
deep_copy
(this)¶ Makes a new instance of a handle class, from https://www.mathworks.com/matlabcentral/newsreader/view_thread/257925
-
distinguishable_colors
(n_colors, bg, func)¶ DISTINGUISHABLE_COLORS: pick colors that are maximally perceptually distinct
When plotting a set of lines, you may want to distinguish them by color. By default, Matlab chooses a small set of colors and cycles among them, and so if you have more than a few lines there will be confusion about which line is which. To fix this problem, one would want to be able to pick a much larger set of distinct colors, where the number of colors equals or exceeds the number of lines you want to plot. Because our ability to distinguish among colors has limits, one should choose these colors to be “maximally perceptually distinguishable.”
This function generates a set of colors which are distinguishable by reference to the “Lab” color space, which more closely matches human color perception than RGB. Given an initial large list of possible colors, it iteratively chooses the entry in the list that is farthest (in Lab space) from all previously-chosen entries. While this “greedy” algorithm does not yield a global maximum, it is simple and efficient. Moreover, the sequence of colors is consistent no matter how many you request, which facilitates the users’ ability to learn the color order and avoids major changes in the appearance of plots when adding or removing lines.
- Syntax:
- colors = distinguishable_colors(n_colors)
Specify the number of colors you want as a scalar, n_colors. This will generate an n_colors-by-3 matrix, each row representing an RGB color triple. If you don’t precisely know how many you will need in advance, there is no harm (other than execution time) in specifying slightly more than you think you will need.
colors = distinguishable_colors(n_colors,bg)This syntax allows you to specify the background color, to make sure that your colors are also distinguishable from the background. Default value is white. bg may be specified as an RGB triple or as one of the standard “ColorSpec” strings. You can even specify multiple colors:
bg = {‘w’,’k’}- or
- bg = [1 1 1; 0 0 0]
will only produce colors that are distinguishable from both white and black.
colors = distinguishable_colors(n_colors,bg,rgb2labfunc)By default, distinguishable_colors uses the image processing toolbox’s color conversion functions makecform and applycform. Alternatively, you can supply your own color conversion function.
Example
c = distinguishable_colors(25); figure image(reshape(c,[1 size(c)]))
- Example using the file exchange’s ‘colorspace’:
- func = @(x) colorspace(‘RGB->Lab’,x); c = distinguishable_colors(25,’w’,func);
-
drop_empty_elements
(cell_array)¶ Removes empty elemtns of cell array. If input is not a cell array returns an empty cell.
-
let_loc
(num_loc)¶ Converts an integer into a column string corresponding to excel tables. source: https://stackoverflow.com/questions/14261648/convert-excel-column-number-to-column-name-in-matlab
-
padcat
(varargin)¶ PADCAT - concatenate vectors with different lengths by padding with NaN
M = PADCAT(V1, V2, V3, …, VN) concatenates the vectors V1 through VN into one large matrix. All vectors should have the same orientation, that is, they are all row or column vectors. The vectors do not need to have the same lengths, and shorter vectors are padded with NaNs. The size of M is determined by the length of the longest vector. For row vectors, M will be a N-by-MaxL matrix and for column vectors, M will be a MaxL-by-N matrix, where MaxL is the length of the longest vector.
Examples
a = 1:5 ; b = 1:3 ; c = [] ; d = 1:4 ; padcat(a,b,c,d) % row vectors
% -> 1 2 3 4 5 % 1 2 3 NaN NaN % NaN NaN NaN NaN NaN % 1 2 3 4 NaNCC = {d.’ a.’ c.’ b.’ d.’} ; padcat(CC{:}) % column vectors
% 1 1 NaN 1 1 % 2 2 NaN 2 2 % 3 3 NaN 3 3 % 4 4 NaN NaN 4 % NaN 5 NaN NaN NaN[M, TF] = PADCAT(..) will also return a logical matrix TF with the same size as R having true values for those positions that originate from an input vector. This may be useful if any of the vectors contain NaNs.
Example
a = 1:3 ; b = [] ; c = [1 NaN] ; [M,tf] = padcat(a,b,c) % find the original NaN [Vev,Pos] = find(tf & isnan(M)) % -> Vec = 3 , Pos = 2
This second output can also be used to change the padding value into something else than NaN.
[M, tf] = padcat(1:3,1,1:4) M(~tf) = 99 % change the padding value into 99Scalars will be concatenated into a single column vector.
- See also CAT, RESHAPE, STRVCAT, CHAR, HORZCAT, VERTCAT, ISEMPTY
- NONES, GROUP2CELL (Matlab File Exchange)
-
printSeparator
(varargin)¶ An ASCII art decorator
Parameters: - nlines (integer) – Number of lines to be printed. A delicate pattern will make them look pleasant.
- centeredMesage (str) – A message which will be printed surrounded by lines. Ignores first argument (nlines).
-
read_dict
(file_path, has_header)¶ Reads a two column csv file into a containers.Map() dictionary. First columns are keys, second columns are values.
Parameters: - file_path (string) –
- has_header (logical, optional) – Default is false.
-
read_sheet
(in_file_path, sheet_name)¶ Returns a map object with the name of the colums and the associted contents for an xls file.
Parameters: - in_file_path (str) – Path of the input file
- sheet_name (str) – Sheet within the xls file indicating the table to be extracted.
-
reformat_cgo
(cgo)¶ Render clustergram object as figure and format nicely.
Parameters: cgo (Matlab's clustergram object) – Returns: - axesHandle (Matlab’s axes handle object.)
- figureHandle (Matlab’s figure handle object.)
-
save_no_overwrite
(out_file_path_name, val, variable_name)¶ Saves file presevering variable name, and appending a number to the end if the input file name already exists.
Parameters: - out_file_path_name (string) – Full paht to the output file
- val (anything that can be passed to a function) – ‘val’ is the entity to be saved.
- variable_name (string) – <variable_name> = val.
-
save_pdf
(filepath, h)¶ Saves figure to pdf of its size
- Args
- filepath(str): full path of output file (extension not required). h(figure handle, optional): default is h = gcf.
-
set_figure_defaults
(f, formatXlabel, formatYlabel, outsideTicks)¶ A set of figure formatting instructions to keep the output consistent and nice looking. All inputs are boolean. Uses global variables which allow for easy configuration.
-
start_parallel
(cores)¶ Starts a parallel pool.
Parameters: cores (integer, optional) – Number of cores, defaults to feature(‘numcores’)
-
write_csv
(filepath, data, verbose)¶ writes a general table stored in a cell to csv file, matlab does not have a function to this… Args
filepath(str) data(cell) verbose(logical, optional): default false