Good programming practice...

Raviteja el 22 de Sept. de 2011
Actividad más reciente Respuesta de Daniel Shub a las el 27 de En. de 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!
Daniel Shub
Daniel Shub el 27 de En. de 2012
It is only fair that if I plug Doug's blog, I should plug Loren's blog also:
Daniel Shub
Daniel Shub el 20 de Oct. de 2011
Fangjun Jiang
Fangjun Jiang el 20 de Oct. de 2011
+1. I remember reading Doug's post. That's a good one.
Steven
Steven el 19 de Oct. de 2011
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.
Jan
Jan el 27 de En. de 2012
@Steven: You have posted this detail 3 times in this thread. Please consider, that the runtime is not affected by the length of the name of the variable, because internally the variable is accessed by a memory pointer taken from a lookup-table. This lookup-table is created when the function is loaded the first time only.
Steven
Steven el 19 de Oct. de 2011
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.
Jan
Jan el 23 de Sept. de 2011
Jan
Jan el 23 de Sept. de 2011
Read the FAQ
It is very likely, that the questions, which concern other users frequently, do concern you also. It is very efficient to profit from the mistakes of others, instead to implement them by your own.
Bjorn Gustavsson
Bjorn Gustavsson el 23 de Sept. de 2011
"It is very efficient to profit from the mistakes of others, instead to implement them by your own." was one of the funniest (sadly fun, funily said) statements I've come across this week!
Daniel Shub
Daniel Shub el 23 de Sept. de 2011
I wish I could vote many many times.
Jan
Jan el 23 de Sept. de 2011
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.
Daniel Shub
Daniel Shub el 23 de Sept. de 2011
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')
Daniel Shub
Daniel Shub el 23 de Sept. de 2011
@jan you are correct, catching the output of load is an important piece of good practice.
Jan
Jan el 23 de Sept. de 2011
Same for SAVE.
And catch the output: Data = load(FileName), otherwise you could find unexpected variables in your workspace like "max", which will shadow existing functions to your surprise. See http://www.mathworks.com/matlabcentral/answers/16484-good-programming-practice#answer_22299
Daniel Shub
Daniel Shub el 23 de Sept. de 2011
Jan
Jan el 23 de Sept. de 2011
I wish, that you do *not* come to Answers, but proceed to the above two links immediately... But I vote the helpful links +1.
Daniel Shub
Daniel Shub el 23 de Sept. de 2011
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.
K E
K E el 26 de En. de 2012
Elements of Matlab Style is great
Raviteja
1
Publicación
1
Responder