MATLAB: Only read data once (with xlsread)

xlsread

Hi there,
I am using xlsread to import data from Excel. This takes quite some time, but that's ok. The real problem is that Matlab loads the data whenever I run the script. Hence, whenever I change a few variables and run the whole script, I have to wait minutes because matlab is working on re-loading the data using xlsread.
Is there any way to only load the data ONCE and not every time I run the whole script?
Any help is much appreciated. Thank you very much.
Best Christian

Best Answer

If the Excel file never changes, one option is to save the data in it as a .mat file. Those are smaller to store and faster to load.
Another option is to create your script as a function and store your Excel file as a persistent variable, then calling your function from a new external script file. Running it as a function instead of a script has disadvantages as well, so consider those and decide if that is an acceptable tradeoff for loading your Excel file each time.
Related Question