xlswrite: output data to excel file {MATLAB functions}

Sometime when a column or a row of data is too long, you can't copy it from MATLAB and then paste directly into an Excel file. A much simpler way to do this is to use the xlswrite function. Just add a line at the end of your code:

xlswrite ('FileName.xls', VariableName)

If you want to put the data into sheet2 in the file, one more input argument is needed:

xlswrite ('FileName.xls', VariableName, 2)

Pretty easy, right?


  1. Thanks for your comment, Anonymous!

  2. hey do u know how to create a for loop and export to different filenames each time the for loop is repeated?

    is the following goin to work?

    for i =1

  3. I think you use the for loop to repeatedly write/save/export xlsx files. However, you need to pay a little more attention to the file name.
    The (i.xlsx) won't work since i is an integer, not a string.

  4. Hello, I am dealing with large quantity of data with the number of rows exceeding Excel's 65526 row limit. I need to export the data into an Excel spreadsheet.

    I want to write a Matlab code which would break down my data into 65526 rows and save them each as a different variable and then save each variable in a new sheet.

    But I am stuck at defining the row range! Could I set my row range as a variable such as this??



    diff=matlab_row - excel_row;


    if diff<0


    I am new with VBA programming, all help is appreciated.


    1. *** I am new with ***C/C++ programming

  5. lets say i want to add 2 vectors....one x and other say y=sin(x) where both x and y are vectors..in to the same excel sheet so that i can create plots of the y vs x kind...so what would i have to change in the command that you have given?

    1. i got it... first do x=x'; and y =y'; so as to make x and y column vectors. then create a matrix z= [x y]; and then the command becomes

      xlswrite('xyz.xls',z,Sheet1,'F5'); that takes care of both the vectors otherwise u have to type out the command twice for each of them (x & y).

  6. how can i adjust the column width of the cells i write into using xlswrite?

  7. give more descriptive answers with examples


Post a Comment

Any comments?

Popular posts from this blog

Set marker edge width in Matlab figures

plotting 3D vector field in MATLAB in many different ways