M-file for exercise!!!
Mostrar comentarios más antiguos
Hi!I have to create an m-file for an exercise and I wanted to ask you what is the difference between a function and a script.Which of them is better??
2 comentarios
per isakson
el 5 de Dic. de 2013
the debugger and the profiler works better with functions
evi
el 5 de Dic. de 2013
Respuestas (2)
sixwwwwww
el 5 de Dic. de 2013
0 votos
If you want to re-use some operation again and again then function is better and if you just wanted to start writing codes in MATLAB then script is better at first. Better or not depends upon functionality usually
8 comentarios
evi
el 5 de Dic. de 2013
sixwwwwww
el 5 de Dic. de 2013
I will suggest you using script first
evi
el 5 de Dic. de 2013
sixwwwwww
el 5 de Dic. de 2013
If you using same parameters in the script and function then you should get the same results. You should take care of values which you input to function and compare those values in the script. If they are same and also implementation in script and function is same then you should get same results beside some minor numerical noise
evi
el 5 de Dic. de 2013
sixwwwwww
el 5 de Dic. de 2013
can you show me both your script and you function? to find the reason for error
sixwwwwww
el 5 de Dic. de 2013
I am getting result both from your script and function. Following are the inputs: For function
test(zeros(50, 1), 50, 0.00001, 50)
For script
Give dimension: 50
Give e: 0.00001
Give maxit: 50
Give x_0: zeros(50, 1)
then why you dont get correct result. Can you check what inputs you give to both your function and script?
Andreas Goser
el 5 de Dic. de 2013
Editada: Andreas Goser
el 5 de Dic. de 2013
0 votos
The documentation for this is also quite good:
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!