MATLAB: Programatically change range of excel sheet depending on data

excelexporting data

Hello everyone,
I am creating an array which may vary in size,especially number of rows.I am exporting this array to an excel sheet. Using : xlswrite('example33.xlsx',er1,'b3:em28') Right below the last row i am doing some other calculations and exporting another array. xlswrite('example33.xlsx',er2(fr,:),'b29:em29') As it becomes obvious if the number of rows from the first array becomes more than what i have specified i lose information. I tried something really logical and practical like xlswrite('example33.xlsx',er1,'b3:max(max(Reading))') %Reading is the array that defines the size of the array i export to excel. But Matlab does not like it.
Does anyone have any idea or previous experience on this matter?
Thank you in advance.

Best Answer

It can be handled. Before you write the array to the Excel sheet, you can use size() function to get the number of rows and columns. xlswrite() allows you to specify the range of the sheet to write to so you just need to "remember" the position of the last writing and properly calculate the position of the next writing.
The only thing you need to do is to have a function to convert a number to the Excel column position. For example, second column means 'B', 26th column means 'Z' and 27th column means 'AA'. The function is called 'dec2base27'. It is inside the xlswrite.m. You need to dig it out and make it a separate function so you can use it. Maybe also dig out the 'base27dec' function too. I've done it and advised several others to do the same. It's quite useful for doing xlswrite().