How to export an array text which created by a string and numbers to excel?

1 回表示 (過去 30 日間)
Khanh
Khanh 2014 年 10 月 4 日
コメント済み: Khanh 2014 年 10 月 4 日
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.

採用された回答

Geoff Hayes
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.
  1 件のコメント
Khanh
Khanh 2014 年 10 月 4 日
While waiting the answer, I wrote the 2nd code to do it. But it consumed more time than the 1st one with your help. Thank you so much.
My 2nd code:
for i=1:length(a)
text={sprintf('WL%d',a(i))};
range=sprintf('a%d',5+i);
xlswrite(filename,text,1,range);
end

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

その他の回答 (0 件)

カテゴリ

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