how to start writing a program ?
47 views (last 30 days)
Show older comments
I think it would be very nice if you could put some comment for a person who want to learn and or start to write a program.
1- what should he/she does at the first step to write a program?
2- which are the most useful commands in Matlab?
3- how can you check if your program works well or not?
4- altogether anything which is useful for a person who wants to write a program
Good writing conveys meaning. Great writing does the same, but uses fewer words.
0 Comments
Answers (6)
Andreas Goser
on 6 Sep 2011
My 2 cents: It is all a matter of goals and skills. Engineers often like to start small and incrementally develop code. Downside is, sometimes it becomes big, slow and unreadable one day. Computer Science people often create a super master plan and structure, but it takes ages until the first piece of real code can be tested. MATLAB should support both strategies.
Last not least. Some people (like me) like to modify existing code.
0 Comments
Paulo Silva
on 5 Sep 2011
- be familiar with MATLAB and read at least documentation Getting Started part
- know what functions are and how to create them (again read the documentation)
- Now for your specific program find exactly what you need to do
- Divide your code into functions so you can develop each part separately
- Every command is useful, there are no most useful commands
- To check if it works well or not give values to the functions arguments and see what happens.
- Finally you learn by doing it and reading the documentation not by doing crazy things with colors and graphics without first knowing how to do the basic and most important stuff, please read the documentation.
0 Comments
Fangjun Jiang
on 5 Sep 2011
My two cents:
- Draw your programming flow chart on paper
- help or doc
- Use the debugging mode to run code step by step
- Start from small to big.
0 Comments
Daniel Shub
on 5 Sep 2011
To me the most useful command is %. That's right comment everything you do. Do use silly end of the line comments. Big chunky blocks of well written clear text explaining in words and sometimes simple math what the code is doing (or at least supposed to be doing.
Some might say that eval, global and cell are the most powerful commands. If you think you need to use eval or a global variable, stop drop and roll. Go get a cup of coffee and think about ways around it. If the coffee doesn't help you get around it, come here and ask. Also be aware of cell arrays. In my opinion they have more legitimate uses then eval and global, but are often used inappropriately.
Finally, don't optimize until you have to. To start with just get your code running. If in the end it takes too long, then optimize with the help of the profiler.
0 Comments
Walter Roberson
on 6 Sep 2011
Andreas is correct, there are different coding styles that suit different needs.
One of my early summer jobs involved helping program an Air Traffic Control System. As it was extremely important that everything be done correctly, years of work had been put in to building a very complete plan of what exactly the system was to do and how it was to do it; the tasks I was given already had their needs and interfaces documented, and I was responsible for following the existing plan and for testing the code strenuously. There are no acceptable "little surprises" when it comes to managing the safety of several 20000 people simultaneously.
The work I am doing now (many years later) involves inventing new mathematical techniques and investigating to see whether those techniques are useful for a particular purpose. The techniques we invent do not have to be perfect and there is good reason to believe that there is no possible "perfect" method for what we are doing.
Unfortunately, when it comes to the creation and testing of new mathematical ideas, it is not at all practical to create detailed plans. To be honest: we make things up as we go along, encountering flaws and coming up with variations. The ideas get polished over time as we "try it and see what happens". And sometimes we don't realize the flaws for several years. "Boss, remember that one-horned one-eyed flying purple people eater algorithm we did a couple of years ago? Well, I just realized that it can't work if the horn is the same purple as the skin." "D'oh!"
0 Comments
See Also
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!