0

I have several Matlab output variables, which I'd like to combine in one Excel sheet, with one column per output variable. If I use the normal 'xlswrite' command, I always get the values of one variable in a row, with the variable name as the file name. But this is not what I want. How can I do this?

2
  • Please share your code, at least the relevant part. Commented Jan 13, 2015 at 15:09
  • 1
    The values will be written the same way they are organised in Matlab. If you write a line [1xn] vector to excel, it will be placed in a row. If you send a column [nx1] vector, it will be in column in excel. Also, you can (have to?) specify a filename to xlswrite, it doesn't have to be the same than the variable name. Commented Jan 13, 2015 at 15:19

1 Answer 1

4

The usage of xlswrite is as follows:

xlswrite(filename,A,sheet,xlRange)

where filename is the string for the filename, A is the data, sheet is an integer for sheet number, and range is a string the range, e.g. 'C1:C2', where C1 and C2 are two opposing corners that define the region to write. For example, 'D2:H4' represents the 3-by-5 rectangular region between the two corners D2 and H4.

So for 2 vectors that you want in 2 columns of the same sheet:

filename = 'pathtofile.xls';
A = vector1;
sheet=1;
xlRange = 'A1:Ax'; %x is size of vector1, or use strcat('A1:A', num2str(len(A)));
xlswrite(filename,A,sheet,xlRange);
A = vector2;
xlRange = 'B1:Bx'; %x is size of vector2, or use strcat('B1:B', num2str(len(A)));
xlswrite(filename,A,sheet,xlRange);

Or you could put them into a matrix and write them into 'Ax:Bx'

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.