MATLAB Answers

Export several arrays with the same name to a xls

1 view (last 30 days)
lightworks on 24 Jun 2013
I have a lot of *.mat, each one containing 3 arrays of the same name, that is:
  • file1.mat contains arrays A1, A2 and A3
  • file2.mat contains arrays A1, A2 and A3 ... and so on.
I need to export them to a xls, like this:
  • Sheet 1 containing, side by side, all the arrays named by A1
  • Sheet 2 containing, side by side, all the arrays named by A2
  • Sheet 3 containing, side by side, all the arrays named by A3
I've been trying for hours now and I can't make it work (my problem is the repeated array's name).
I loaded all the files with this (I don't even know if it's the right way):
s = what('./matrices/Tmax/');
for i=1:numel(matfiles);
x=load(['./matrices/Tmax/' char(matfiles(i))]);
I'd really appreciate any help. Thanks in advance!


Sign in to comment.

Accepted Answer

Leah on 24 Jun 2013
This will work up to the Z column in Excel (26 mat files) I don't know how many mat files you have.
mat_files=1:26; %number of mat files
excel_col=double('A'); %starting Excel Column
for m=mat_files
load(['file' num2str(m) '.mat']);


lightworks on 24 Jun 2013
I think I didn't make myself clear.
The name of the *.mat files are not in a number sequence, they are just like: John.mat, Maria.mat, etc. So insted of loading with num2str I had to use the way I said in the first post.
So I tried out your code modified like this:
s = what('./');
excel_col=double('A'); %starting Excel Column
for i=1:numel(matfiles);
load(['./' char(matfiles(i))]);
Where I also modified that the increment is i*7-1 insted of i-1. I did this because each of my arrays contains 7 columns (I don't know if it's the right thing to do).
But I get this error:
??? Error using ==> xlswrite at 213 Excel returned: Error: Object returned error code: 0x800A03EC.
Error in ==> test at 11 xlswrite('output.xls',A1,'A1',char(excel_col+i*7-1));
What did I messed up?
Thanks a lot for your help!
Leah on 24 Jun 2013
Your modification is correct and the code works for me. Must be something specific to your data. My dummy data is just a bunch of numbers. Check out this info for possible solutions to that error code.

Sign in to comment.

More Answers (0)


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!