MATLAB: How to save all data from a loop in excel

3dexcel

I calculate statistical values like Entropy, Energy, Mean etc from a 3D image..So I use a loop to go through all slices of the image and calculate the values..How can I save the values of all the slices in excel in different columns each time?

Best Answer

Instead of writing each column in an excel file (which takes a lot of time, since each time you should get access to memory) it is better to save your result in a variable (it might be easier to use a table structure) and save that variable in an excel file finally. then you can easily write that variable in an excel file:
xlswrite('test.xlsx', variable)