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

Simple MATLAB to Excel Question

  1. Jun 19, 2012 #1
    I've discovered that MATLAB is not my forte. I have a 51x3 matrix that I want to print to an Excel sheet, but with column headers. I can get the matrix into an Excel file and I can get the headers into an Excel file, but I cannot figure out how to get the two together. I've looked up how to do this and it is not working for me.

    What I have is

    Code (Text):
    sunAngleMtx(:,1) = results.Timestamp;
    sunAngleMtx(:,2) = results.SubTargetID;
    sunAngleMtx(:,3) = results.SunAngle;

    data = {'Timestamp','SubTargetID','SunAngle'; sunAngleMtx};
    xlswrite('sunAngleData.xls', data);
    and I'm getting the error
    Any idea what I'm doing wrong. I imagine this is just me being a MATLAB noob.

    Thanks in advance.
  2. jcsd
  3. Jul 26, 2012 #2
  4. Jul 26, 2012 #3


    User Avatar

    Staff: Mentor

    How? Other people might find it useful. :smile:
  5. Jul 26, 2012 #4
    Code (Text):

    data = 'Timestamp,SubTargetID,SunAngle\n';
    fout = fopen('sunAngleData.csv','wt');
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook