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.

채택된 답변

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 CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by