Issue with writing multiple variable to excel sheet

3 ビュー (過去 30 日間)
Karthik KJ
Karthik KJ 2013 年 4 月 17 日
Hi,
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) http://www.mathworks.com/matlabcentral/fileexchange/10465-xlswrite1
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?

回答 (2 件)

Ahmed A. Selman
Ahmed A. Selman 2013 年 4 月 17 日
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:
A=[a1
a2
a3
...]
b={'name1'
'name2'
'name3'
...etc}
then use xlswrite('excelFileName',A,Range)..etc.

Iman Ansari
Iman Ansari 2013 年 4 月 17 日
Hi
a=[1 1 1];
b={'name'};
xlswrite('New.xlsx',a,1,'A1')
xlswrite('New.xlsx',b,1,'D1')
  2 件のコメント
Karthik KJ
Karthik KJ 2013 年 4 月 17 日
As i told before, if i use xlswrite it works, but matlab has to open and close excel each time, which takes huge amount of time if i have more than 1000's of iterations. So thats why i used xlswrite1.
Iman Ansari
Iman Ansari 2013 年 4 月 17 日
This works with xlswrite1 too:
a=[1 1 1];
b={'name'};
xlswrite1('New a.xls',a,1,'A1')
xlswrite1('New a.xls',b,1,'D1')

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by