- 1、本文档共18页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Matlab矢量化编程集锦(国外英文资料)
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
文档评论(0)