Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
XLSWRITE

Subject: XLSWRITE

From: Philosophaie

Date: 10 Jun, 2009 03:32:01

Message: 1 of 2

I have got xlsread to take a range from a .xls file and assign it to an array. I now want use xlsread to take an array and write it to a .xls file. This is what I have thus far:

for i = 1:25
    N(i, 1) = Num(i)
    N(i, 2) =Name(i)
end
xlswrite('C:\path\file.xls', N(:, :), 'K2')

The xlswrite should write starting from cell K2 with N(:, :) in C:\path\file.xls. This does not work. Could someone show me why not.

Subject: XLSWRITE

From: Darren Rowland

Date: 10 Jun, 2009 03:43:01

Message: 2 of 2

"Philosophaie" <ertlejack@sbcglobal.net> wrote in message <h0n9fg$h2d$1@fred.mathworks.com>...
> I have got xlsread to take a range from a .xls file and assign it to an array. I now want use xlsread to take an array and write it to a .xls file. This is what I have thus far:
>
> for i = 1:25
> N(i, 1) = Num(i)
> N(i, 2) =Name(i)
> end
> xlswrite('C:\path\file.xls', N(:, :), 'K2')
>
> The xlswrite should write starting from cell K2 with N(:, :) in C:\path\file.xls. This does not work. Could someone show me why not.

From the xlswrite doc
____________________
Specify range using the syntax 'C1:C2', where C1 and C2 are two opposing corners that define the region to write. For example, the range 'D2:H4' represents the 3-by-5 rectangular region between the two corners D2 and H4 on the worksheet. The range input is not case sensitive and uses the Excel A1 reference style. (For more information on this reference style, see Excel help.) xlswrite does not recognize named ranges.

The size defined by range should fit the size of M. If range is larger than the size of M, Excel software fills the remainder of the region with #N/A. If range is smaller than the size of M, xlswrite writes only the submatrix that fits into range to the file specified by filename.

      Note If you specify only three inputs, xlswrite must decide whether the third input refers to a sheet or a range. To specify a range, include a colon character in the input string (such as 'D2:H4'). If you do not include a colon character (such as 'sales' or 'D2'), xlswrite interprets the third input as a value for sheet.
_______________________

So your string 'K2' is being interpreted as the sheet number, not the cell number.
You must include the final cell as well to define the range
Hth
Darren

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us