How to export an array text which created by a string and numbers to excel?
1 次查看(过去 30 天)
显示 更早的评论
Hi,
I have a numeric array a=0:100:1000
I want to precede each element of the array with 'WL' and I will get a new array: 'WL0', 'WL100', 'WL200',..., 'WL1000'.
Then I will export it excel by xlswrite. Could someone please help me to do it? I wrote by myself but I couldn't get the result I desired.
Here is my code:
clc
clear all
format short
a=0:100:1000;
wl={};
for i=1:length(a)
text=sprintf('WL%d',a(i));
wl={wl;text};
end
xlswrite(filename,wl,1,'A6');
Thanks.
0 个评论
采纳的回答
Geoff Hayes
2014-10-4
Khanh - you almost have it. w1 has been (correctly) defined as a cell array, it is just the vertical concatenation that is failing at the line
wl={wl;text};
which seems to result in a 2x1 object where the first is a cell array, and the last is the last value added (text). Just change this line to the following which will create the column that you desire
wl=[wl;text];
and assign a filename
filename = 'myExcel.xls'
and you should be good to try again.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!