Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

MATLAB Append new columns into Excel

  1. Jun 20, 2016 #1


    User Avatar
    Gold Member

    I would like to ask how to use MATLAB to append new columns into existing excel file without altering the original data in the file? In my case I don't know the original number of columns and rows in the file and it is inefficient to open the files one by one and check in practice. Another difficulty is that the new columns may have different number of rows to the existing data so that I cannot use the trick of reading in the data, forming a new matrix and replace the data with the new matrix.

    I have seen many posts teaching people how to add new rows but adding new column seems quite a different thing since the columns are named by letters instead of numbers.

    Thank you.
  2. jcsd
  3. Jun 20, 2016 #2


    Staff: Mentor

  4. Jun 20, 2016 #3


    User Avatar
    Gold Member

    Finally I solve it in the following way:

    if (step==1)
    xlswrite(filename,array,sheetname,'A1'); %Create the file

    [~,~,Data]=xlsread(filename,sheetname); %read in all the old data

    OriCol=size(Data,2); %get the column number of the old data

    NewCol=OriCol+1; %the new array is placed right next to the original data





    The xlcolumnletter function is found here:
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted