Good programming practice...
Raviteja
on 22 Sep 2011
Latest activity Reply by Daniel Shub
on 27 Jan 2012
Hello all,
Please explain good MATLAB programming practice methods. It will help to the guys who are new to programming like me.
Previously I used
for i=1:10
after following some suggestions from this answers pages I learnt to use
for i1=1:100
This is the good way to write programs.
Like this, as a professional programmer, please mention some good programming practice techniques.
It will useful to all!
40 Comments
Time DescendingIt is only fair that if I plug Doug's blog, I should plug Loren's blog also:
Surprised Doug didn't chime in with his blog post: http://blogs.mathworks.com/videos/2010/03/08/top-10-matlab-code-practices-that-make-me-cry/
However, the difference seems to be indistinguishable considering a certain precision whatever the number of repetitions.
tic;
for i1 = 1:100000
x = sin(i1);
end
toc
Elapsed time is 0.003597 seconds.
tic;
for i = 1:100000
x = sin(i);
end
toc
Elapsed time is 0.003569 seconds.
However, the difference seems to be indistinguishable considering a certain precision.
tic;
for i1 = 1:100000
x = sin(i1);
end
toc
Elapsed time is 0.003597 seconds.
tic;
for i = 1:100000
x = sin(i);
end
toc
Elapsed time is 0.003569 seconds.
Read the tips for program development in the dokumentation:
And if you are on the way, read the rest of the documentation also, at least the "Getting Strarted" chapters.
Use the functional form of load and save, and almost every other function except maybe help and doc
instead of
load filename.mat
use
data = load('filename.mat')
Come to Answers before using global or eval. There is almost always a better way to do it.
I suggest developing a coding "style." Some good places to start are given in the FAQ:
I also would consider this book reviewed by Loren
although I should say I have not looked at it yet. It is on my list of things to do.
Sign in to participate