How to declare a structure as global

3 views (last 30 days)
Komali Usse
Komali Usse on 16 Apr 2012
How can I access a structure defined in a for loop, outside the for loop??

Answers (2)

Walter Roberson
Walter Roberson on 16 Apr 2012
Any variables defined within the loop will continue to exist after the loop, until the defining function returns.
If you are defining the structure in the for loop, are you possibly overwriting the structure in each iteration of the loop? That could be a problem for you.

Tom
Tom on 16 Apr 2012
The easiest way would be to preallocate it from outside the for loop. In MATLAB, you don't have to declare variables, but you can create the variable and fill it with zeros, or empty strings, ' '.

Categories

Find more on Loops and Conditional Statements 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!