Case 1:
I have a nested for loop to run large realizations and save variables generated through that loop in .mat files, which I can later use in another program.
Case 2:
I can make the function of the above mentioned loop and call it directly in the other program where I want to use the variables generated by the above loop.
The only disadvantage I find of Case 1 is that every time I make some changes in that loop, I must run it again and save the updated variable.
- Which case among the above two cases is the better option?
- Whi开发者_运维技巧ch would be more fast - a) if I run that loop directly in the main program (not using .mat file), or b) develop a function for that loop and then call it in the main program?
Saving your data in a .mat file only makes sense if you can economize computing time. File input & output is rather slow in matlab. Keeping your data in memory is therefore faster.
In cases where your data 'preprocessing' only takes place once and the result is used again and again in later processing stages, storing the preprocessed data may be an option.
精彩评论