samedi 5 novembre 2011

Matlab: passing an input argument to a script

Assalamo 3alaykom :)

So, I had this routine to run in matlab and I got tired  copying and pasting all the code and then change the values of my variables, so I had to find an easy way  to get trough with this...the solution was clear and trivial just pass your variables as input argument to the script!!! Why didn't  think of it earlier :-/
Then came the syntax problem how do i do this in matlab?
After a quick google search this is what I found:
assume that we want to calculate "sqrt(x)", our script will look like this:
now we have 2 ways to pass the argument "x" to the script:

1- just type the value of "x" in the command window before running the script:

2- or, convert the script to a function by adding the folowing line to the beginning of your script:function y=scriptFileName(x)
then run your function on the command window as follows:
>> scriptFileName(36)

That's it: easy peasy lemon squeezy

0 commentaires: