Creating arrays in auxiliary functions

12 views (last 30 days)
António
António on 13 Jul 2014
Commented: Image Analyst on 13 Jul 2014
Hello.
This is how I have my code organized:
function main()
...
function auxiliary1()
...
function auxiliary2()
...
etc..
When I create an array, A(k) inside one of the auxiliary functions, as k increases the previous values of A turn into zero. Does this means that I can only construct an array inside the main function (where k is counting)?
Thank You

Answers (2)

Azzi Abdelmalek
Azzi Abdelmalek on 13 Jul 2014
If you want your variable k to be seen by all your functions, declare it as global in each function, or pass the variable k as input argument in each function
  7 Comments
António
António on 13 Jul 2014
As you see, I am creating x_T(k) in the getCoordTransf function. I call that function inside a while loop, in the main function. However, when I ask to "see" x_T (after the loop), all it's members are zero, except the last one. I've already figured an alternative (not very elegant). Thank you.

Sign in to comment.


Image Analyst
Image Analyst on 13 Jul 2014
  1 Comment
Image Analyst
Image Analyst on 13 Jul 2014
In main(), do this
x_T(k) = getCoordTransf(Ehat,AA,BB,CC,k);
In getCoordTransf(), do this:
x_T = dot((...........

Sign in to comment.

Categories

Find more on Multidimensional Arrays 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!