Global Variables turn to empty ones once called inside a function?
이전 댓글 표시
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.
답변 (1개)
Walter Roberson
2016년 12월 4일
3 개 추천
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.
카테고리
도움말 센터 및 File Exchange에서 Variables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!