In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
How to understand the matlab function, I believe that many inexperienced people are at a loss about it. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
PadSize function
Paste the matlab source code
Function [pad_ul, pad_lr] = PadSize (offsets,op_type) if isempty (offsets) pad_ul = zeros (1Magazine 2); pad_lr = zeros (1Power2); else num_dims = size (offsets {1}, 2); / / find the maximum dimension for k = 2:length (offsets) num_dims = max (num_dims, size (offsets {k}, 2)) End for k = 1:length (offsets) / / establish a large matrix offsets {k} = [offsets {k} zeros (size (offsets {k}, 1),... Num_dims-size (offsets {k}, 2)]; end pad_ul = zeros (1Magneto numnumbildims); pad_lr = zeros (1ZHINONUBIMS); for k = 1:length (offsets) / / find the minimum value in the matrix offsets_k = offsets {k}; if ~ isempty (offsets_k) pad_ul = pad_ul + max (0,-min (offsets_k, [], 1)) Pad_lr = pad_lr + max (0, max (offsets_k, [], 1)); endend if strcmp (op_type,'erode')% Swap tmp = pad_ul; pad_ul = pad_lr; pad_lr = tmp; endend
Input: offsets is 1-6 cell
Max (offsets_k, [], 1) offsets_k is a matrix of 5 times 2-
2-2
-1-1
0 0
1 1
2 2
Post a detailed explanation: http://blog.sina.com.cn/s/blog_505018ce0101976j.html
On the MAX function in MATLAB
One: several forms of MAX function
(1) max (a) (2) max (AMaginb) (3) max (a, [], dim) (4) [Cpene I] = max (a) (5) [Cpene I] = max (a, [], dim)
Second, give an example to illustrate the meaning of the function.
(1) max (a)
If an is a matrix, for example, max (a) means to find out the maximum value of each column of the matrix, in this case: max (a) = [4p5]
(2) max (aPerm b)
If both an and b are matrices greater than 1 dimension, then the dimensions of the rows and rows of an and b are required to be equal, and the result of the function is to compare the size of each element in an and b, such as:
A = [1, max, 2, 3, 4, 4, 7, 8, 6] b = [4, 5, 5, 6, 6, 7, 7, 8, 8, 6] (a) = [4, 5, 5, 6, 6, 6] in addition, if at least one of an and b is constant, it is also possible. For example: a = [1, 2, 3, 4, 5, 6] baked 3 cages 5
Max (b) = [3 max (b) = 3, 3, 3, 3, 10, 4, 5, 5] I believe we all understand the meaning of the function after seeing the example, right?
(3) max (a, [], dim)
This function means for a two-dimensional matrix, and dim is the abbreviation of the English letter dimension, which means dimension. When dim=1, the rows of a matrix are compared, that is, the effect is the same as max (a); when dim2, the rows of matrix an are compared. Here's an example:
Max (a) = max (a, [], 1) = the values of the first and second rows of comparison max (a, [], 2) = [3jue 6]
(4) [CMI] = max (a)
C represents the maximum value of each column of the matrix a, and I represents the subscript corresponding to each maximum value: the following example:
It's the same example as before: a = [1, max, 2, 3, 10, 4, 5, 5, and 6] [C ~ (1) I] = (a)
The result shows that the line number corresponding to the maximum value is returned by C = [4penny 5pr 6] I = [2je 2pr 2].
(5) [CMI] = max (a, [], dim)
By the same token: if you dim=1, the result is the same as [cMagne] = max (a). When dim=2, the same matrix an above, let's run:
The result is: C = [3jue 6] I = [3jue 3] I returns the column number of the matrix a.
Ndims () function
The result returned by ndims (A) is actually equal to length (size (A)).
Generally speaking, the array dimension is the direction of the array. For example, the ordinary two-dimensional array, the array has row direction and column direction, that is, the array has two directions, is a two-dimensional array. You can also create three-dimensional or higher-dimensional arrays in MATLAB.
For empty arrays, scalars, and one-dimensional arrays, MATLAB is still treated as a normal two-dimensional array, so they all have at least two dimensions (at least row and column orientation). In particular, an empty array generated by blank square brackets is treated as a two-dimensional array, but there is also the concept of an empty array in a high-dimensional array, when the empty array can be an array whose size is equal to zero only in any dimension, accordingly, the empty array at this time has multiple dimensions.
You can use the function ndims to calculate the array dimensions in MATLAB.
The result returned by ndims (A) is actually equal to length (size (A)).
[example 3-13] Array dimension.
Solution: after entering the command, the running result is as follows:
> > Bamboo 2
B =
two
> > ndims (B)
Ans =
two
> > cymbals 1purl 5
C =
1 2 3 4 5
> > ndims (c)
Ans =
two
As you can see from examples 3-13, general non-multidimensional arrays are treated as two-dimensional arrays in MATLAB.
Post a function: link http://blog.sina.com.cn/s/blog_83057b2401012rxj.html
Function: fill an image or fill an array
Use:
B = padarray (A _
An is the input image and B is the filled image. Padsize gives the number of rows and columns filled, which is usually expressed by [r c]. Padval and direction represent the filling method and direction, respectively. Their specific values and descriptions are as follows:
Padval:'symmetric' indicates that the image size is expanded by mirrored reflection around the boundary.
'replicate' indicates that the image size is expanded by copying the values in the outer boundary
The circular' image size is expanded by treating the image as a period of a two-dimensional periodic function.
Direction:'pre' means to fill in before the first element of each dimension.
'post' means to fill in after the last element of each dimension
'both' indicates that it is populated before the first element and after the last element of each dimension, which is the default value.
If direction is not included in the parameter, the default value is' both'. If the parameter does not contain padval, it is filled with zero by default. If no parameter is included in the parameter, the default padding is zero and the direction is' both'. At the end of the calculation, the image is trimmed to its original size.
[a, method, padSize, padVal, direction] = ParseInputs (varargin {:}); if isempty (a),% treat empty matrix similar for any method if strcmp (direction,'both') sizeB = size (a) + 2roompadSize; else sizeB = size (a) + padSize; end b = mkconstarray (class (a), padVal, sizeB); else switch method case 'constant' b = ConstantPad (a, padSize, padVal, direction) / the functions are: case 'circular' b = CircularPad (a, padSize, direction); case' symmetric' b = SymmetricPad (a, padSize, direction); case 'replicate' b = ReplicatePad (a, padSize, direction); end endif (islogical (a)) b = logical (b); end
Function b = ConstantPad (a, padSize, padVal, direction)
NumDims = numel (padSize)
% Form index vectors to subsasgn input array into output array.
% Also compute the size of the output array.
Idx = cell (1mam numDims)
SizeB = zeros (1mam numDims)
For k = 1:numDims
M = size (amam k)
Switch direction
Case 'pre'
Idx {k} = (1 M) + padSize (k)
SizeB (k) = M + padSize (k)
Case 'post'
Idx {k} = 1Rom M
SizeB (k) = M + padSize (k)
Case 'both'
Idx {k} = (1 M) + padSize (k)
SizeB (k) = M + 2*padSize (k)
End
End
% Initialize output array with the padding value. Make sure the
% output array is the same type as the input.
B = mkconstarray (class (a), padVal, sizeB)
B (idx {:}) = a
After reading the above, have you mastered how to understand the matlab function? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.