Global Variables turn to empty ones once called inside a function?
Mostra commenti meno recenti
I have one main program, in which I set a variable
prop = [210000 0.3 4];
The cells from variable prop are called inside a function like this:
1->E=prop(1);
2->v=prop(2);
3->t=prop(3);
I ran the Main program and it gave me the Error "Index exceeds matrix dimensions" on line 1.
I declared prop matrix as global in both main script and function .
I ran it on debug mode and I realised that, even when prop matrix is declared global in both main script and function, once the function is called, on the workspace prop matrix is empty, like below:
prop=[]
Why is this happening, since I have declared the matrix as global? How can I fix this?
Thanks in advance.
Risposte (1)
Walter Roberson
il 4 Dic 2016
3 voti
The above would happen if you declare the variable to be global after you initialize it. It would also happen if you did not declare the variable to be global in the same workspace that you initialize it.
Categorie
Scopri di più su Variables in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!