文档详情

Matlab矢量化编程集锦(国外英文资料).doc

发布:2017-06-08约1.03万字共18页下载文档
文本预览下载声明
Matlab矢量化编程集锦(国外英文资料) reference Spymatlab vectoring programming technique of the spy1120 Painted levels: It is often found that some Matlab beginners write code with layers of code that are often slow and difficult to understand. Matlab provides a number of commands to avoid loops Advice: in sure you want to write a 2 heavy cycle before the matrix operations, please read it carefully to help in Maximizing the MATLAB Performance section. There are a lot of examples, heres one of my own problems: To figure out the maximum brightness of the digital image and the minimum, since the digital image might be a two-dimensional or three-dimensional matrix, I wrote the following code: The switch ndims (img) Case 2 M = Max (img); Case 3 M = Max (Max (img)); The end And then I was very unhappy with that, and if I had an eight-dimensional matrix, I would write it Max (Max (Max (Max (Max (x)))))) To just go? And it turns out that no matter what the dimension of the matrix is, actually Max (x (:)) It is enough. The comment: y = x (:) will return all the elements of the matrix to form a column vector y, regardless of the dimension of x. Note: y is aligned in the way x is prioritized Level: yes Problem: extract the blue portion of an RGB image Answer: [Copy to clipboard] [-] CODE: A = imread ( input. BMP ); H equals size of A; BB = repmat (255, H (1) * H (2), H (3)); C = (A) (:, 1) = = 0 A (:, 2) = = = 0 A (:, 3) = = = 255); BB (C, 1) = 0; BB (C, 2) = 0; B = reshape (BB, H (1), H (2), H (3)); Imwrite (B, output.bmp); Comment on: the use of the note repmat and reshape. Solution is the key to reshape command flexible use of the 3 d matrix into A two-dimensional matrix, thus making the subscript matrix of satisfy the conditions C can be reference to the original matrix A. Otherwise, this kind of problem must not be out of the loop. Painted levels: Problem: assignment of skills - when many elements in the matrix at the same time (below zero, for example, and does not consider the spars
显示全部
相似文档