Matlab scripts that provide some simple quality of life functions while performing transformations on data or datatype conversions. This is a supporting submodule for other repositories.
Quantises a grayscale image consisting of floating point data into an integer representation with an associated lookup table. LUT_Entries dictates the number of grayscale levels, Linear_Interp set to true forces the LUT to be spaced linearly rather than by using pchip for non-evenly distributed data (false, default).
Image = rand(100, 100);
LUT_Entries = 100;
Linear_Interp = true;
[Index_Sorted, LUT_Sorted] = Array_To_Index(Image, LUT_Entries, Linear_Interp)Converts a binary vector to a floating point number.
Binary = '0011111111110100110011001100110011001100110011001100110011001101';
Float= Binary_To_Float(Binary);
Float = 1.3;Converts a string to a vector of bit values.
Bit_Vector = [0 1 0 1 1 1 1 0];
Bit_String = Bit_String_To_Vector(Bit_Vector);
Bit_String = '01011110';Converts a vector of bit values to a string of 1's and 0's.
Bit_Vector = [0 1 0 1 1 1 1 0];
Bit_String = Bit_Vector_To_String(Bit_Vector);
Bit_String = '01011110';Converts a floating point number into a binary string.
Float = 1.3;
Binary = Float_To_Binary(Float);
Binary = '0011111111110100110011001100110011001100110011001100110011001101';Avoids floating point calculation errors with extremely small numbers. This function is capable of comparing
- Two scalars
- One vector against one scalar
- Two equally sized vectors.
%Create a vector and scalar value to compare
A = rand(5,1);
B = rand(1);
%Get array with the comparison results
Boolean_Vector = Floating_Point_Equal(A, B);Circular reference to a figure. If no inputs are supplied, a new figure is created. If a figure is specified by one instance of this function, on the next iteration of the loop it will re-select this figure as being active. This function must be called initially with no input to generate the initial window. The figure can be shown (default) or shown by specifying Hide_Figure as being true.
%Create two figures initially
Hide_Figure = false;
Figure_1 = Get_Figure();
Figure_2 = Get_Figure();
for i = 1:10
%re-select first figure
Figure_1 = Get_Figure(Figure_1, Hide_Figure);
%Plot stuff
%re-select second figure
Figure_2 = Get_Figure(Figure_2, Hide_Figure);
%Plot stuff
end2-dimensional moving standard deviation that creates a window of size (2K + 1) by (2K + 1).
Data = rand(50);
K = 2;
%Creates a 5x5 window calculating a moving standard deviation across Data
Std_Dev = Moving_STD_2D(Data, K);Does a 2D convolution while ignoring NaN values. Varagin allows various parameters to be set regarding the shape, edges and dimensionality of the inputs (information found within the script for more information).
Data = rand(50);
K = 2;
Convolution = NaN_Conv(Data, K, varargin);- Alex Hogg - Initial work - Phy3hogga
- Eric Verner - Binary and Bit String conversion1 - Matlab File Exchange
- Benjamin Kraus - 2D convolution ignoring NaN values2 - Matlab File Exchange