You can use the following code snippet in MATLAB to add variables to an array sequentially inside a loop:
main.m258 chars9 lines
In this code, my_array is initialized as an empty array. Inside the loop, the some_function is called to produce a variable current_var that is then added to the end of my_array. The end+1 index in my_array(end+1) adds the variable to the end position of the array, hence enabling sequential addition of variables.
You can change num_elements to the number of elements that you want to add to the array.
gistlibby LogSnag