Look at everyone in this question (why do many programmers think that MATLAB language design is not elegant or even more ugly?) Can you cite some examples to illustrate this? -mathematics) under the chill of the groove, on the back. Because of the historical reasons in the group, the language is not realistic ...
My own experience is to use MATLAB to write small-scale (within 1000 lines) of the GUI is very fast, interactivity is not particularly strong GUI can be done directly with the guide. However, the complexity of the code increases with the square of the code length.
Ask how to improve the programming style of writing code with MATLAB, write simple and easy to maintain procedures?
Reply content:
It's a little messy to think about it.
Use deal to implement a "one-line assignment of multiple values" in Python.
[H,W,N]=deal(42); % H = 42, W = 42, N = 42[H,W,N]=deal(28,28,32);% H = 28, W = 28, N = 32, respectively
Ah, thank you, Brother @ Watanabe Zoet invitation.
is not very good at writing Matlab, I just said to see some of the MATLAB code problems and suggestions.
The first is the design pattern,
Some MATLAB engineer does not have the design pattern, generally is a small process of the demo expansion into a large program, the code has a lot of duplicated code, in fact, after the command line based on the completion of the demo should consider to design a kind of program, and then re- Reduce the need for each line of code to take advantage of every available data.
The second is the management of data structure,
MATLAB provides a very convenient data structure, how to use them is a big problem, in this regard, it should be said to minimize each line of their own handwritten code, before using each feature Google has built-in support, take 10 minutes to see the document understanding the merits of the support Then use the Matlab language designer's thinking to write Matlab.
Matlab users seem to like to use global variables, which in itself is understandable, global variables sometimes lead to some problems, you can use a namespace-like method to differentiate.
The third is the management of the Code,
Amateur programmers sometimes have the problem of using annotations to copy and paste and compress files to manage code so that the code becomes unreadable in a slightly larger system, and the engineers don't know what they're doing, and my advice is to spend an afternoon learning about Git
The forth is the structural separation,
The GUI can be designed to conform to MVC, view, control, data separation, as much as possible each. m files have their own functions, each function logically separated. Of course you can do a little lighter. Individuals do not like to put files too long.
The other is to use a higher-order programming paradigm,
Matlab can be written oo some, but MATLAB for functional programming support is not very good, because there is not much to write about.
The above is I read some engineers, scientists code to see some of the problems, and not limited to MATLAB, if there is improper also please more advice. Alas, I will slowly update my study notes.
1. Code style:
After the question to Google a bit, the following guideline can refer to:
MATLAB Style Guidelines 2.0
2. How to gracefully write a GUI
StackOverflow fix GUI code bad problem: Matlab-what's the "right" approach to organize GUI codes?
Official document: Writing Apps in MATLAB
。
Example: File Exchange
An example of using OO GUI, looks great.
3. "Encapsulate" the program using the app function
4. Google
There is no need to reinvent the wheel, most of the problems have been met and solved. Therefore, you can solve the problem in a few minutes, Google solution. After all, most of the users of MATLAB are not program development experts, most of the time get things done is a good attitude.
Here's another question:
the foundation is not good, encounters the question to search what key words do not know.
My stupid way is to ask senior brother, go to StackOverflow and mathwork on the website to ask questions, or simply sweep the book quickly, only pay attention to concepts and definitions, ignoring technical details.
5. Use Genuine
If there is a genuine word, the use of genuine bar, encountered problems can be directly called Mathwork technical support, can also save a lot of time.
Alas, it seems that MATLAB is not so no medicine to save it. I am doing engineering application, I think a good algorithm only get the application is good algorithm, so I personally do not advocate the use of Natlab gui,matlab do algorithm analysis concise and efficient, logic enough complex, Human-computer interaction is not necessary to do Matlab GUI.
In fact, the above answer is about OO style, because of the reason for design ideas. The idea of design mode is can be used, if you used to be relatively familiar, in the MATLAB learning side use or forget it.
I think that can directly according to the original translation of C + + MATLAB Program is a good program, this is an algorithm out of the theory, put into application of the ultimate destination.
In other words, when you can use C + + to do the algorithm without obstacles, you easily do not want to come back with Matlab, unless it is some middle process to show the cumbersome to take MATLAB analysis.
In other words, I personally think that Windows and Matlab to the Chinese university students harm is really difficult to measure, we started with the most tall mature tools, but neglected their bottom-up implementation and design ideas, know and realize is two levels, In need of creative time experience and means can show the role, can not rob the opportunity, lost the hand, if you have to read the children of the University, it is recommended to use those open source operating system and numerical algorithms, do not covet convenience, in the most need to think and practice age from waste martial arts, thinking and practice of the pavilion built in the air. Matlab Dafa is really good! But I just don't like it.
Ask why.