Issue with writing multiple variable to excel sheet

5 views (last 30 days)
Karthik KJ
Karthik KJ on 17 Apr 2013
I have three interger values and one string. I need to write it to excel sheet. I have tried to concatenate three integers to a single variable but for the strings i cant concatenate.
a=[1 1 1], b={'name'}
How do i write all these variable to the excel sheet to range of A1:D1, D1 should have the string.
I have thousands of similar data to write to excel, so i use xlswrite1, since i dont want matlab to open and close everytime(this happens if is use standard xlswrite)
so in this case if i write xlswrite1 for writing variable 'a' and then xlswrite1 for writing variable 'b' in next line, then i get the error, as the excel sheet is already open.
So is there any alternate way to do the xls writing?

Answers (2)

Ahmed A. Selman
Ahmed A. Selman on 17 Apr 2013
It is not practical to write a single line in an excel file, for a large amount of data or inside a long-time running loop. If your task is to do so, then it's natural to take to infinity to finish, no matter the type of the function you've used, because Matlab has to open the excel file when writing to it and close it afterwords.
But you can first concatenate two large matrices within the loop, one for numeric values and the other for string, then write the matrices into the excel file using a single command, that is as:
then use xlswrite('excelFileName',A,Range)..etc.

Iman Ansari
Iman Ansari on 17 Apr 2013
a=[1 1 1];
Iman Ansari
Iman Ansari on 17 Apr 2013
This works with xlswrite1 too:
a=[1 1 1];
xlswrite1('New a.xls',a,1,'A1')
xlswrite1('New a.xls',b,1,'D1')

Sign in to comment.


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!