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?
1 Answer
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'
line[1xn] vector to excel, it will be placed in a row. If you send acolumn[nx1] vector, it will be in column in excel. Also, you can (have to?) specify a filename toxlswrite, it doesn't have to be the same than the variable name.