Simple MATLAB to Excel Question

  • Context: MATLAB 
  • Thread starter Thread starter swartzism
  • Start date Start date
  • Tags Tags
    Excel Matlab
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
3 replies · 3K views
swartzism
Messages
103
Reaction score
0
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:
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
Error using vertcat
CAT arguments dimensions are not consistent.

Error in sunAngleCheck (line 12)
data = {'Timestamp','SubTargetID','SunAngle'; sunAngleMtx};

Any idea what I'm doing wrong. I imagine this is just me being a MATLAB noob.

Thanks in advance.
 
on Phys.org
Code:
data = 'Timestamp,SubTargetID,SunAngle\n';
fout = fopen('sunAngleData.csv','wt');
fprintf(fout,data);
fprintf(fout,'%d,%f,%f,%f,%f,%f\n',sunAngleMtx');
fclose(fout);