Convert .mat file into .xls file

67 views (last 30 days)
amit matlab
amit matlab on 10 Aug 2020
Answered: Walter Roberson on 10 Aug 2020
I am try to convert the attached mat file into xls file. I check some previous answer but it didnot work in my case.
  1 Comment
Sulaymon Eshkabilov
Sulaymon Eshkabilov on 10 Aug 2020
Hi Amit,
This is how you can write your *.mat file data into *.xlsx file:
xlswrite('TEST.xlsx', TestIndex', 'TestIndex');
for ii = 1:36 % 36 cells in ROI
SH=strcat('ROI', num2str(ii));
xlswrite('TEST.xlsx', [ROI{1,ii}.Xaddress', ROI{1,ii}.Xaddress', ROI{1,ii}.Yaddress', ROI{1,ii}.Polarity', ROI{1, ii}.TimeStamp'], SH);

Sign in to comment.

Answers (2)

Sudheer Bhimireddy
Sudheer Bhimireddy on 10 Aug 2020
Follow the example given on that page. If you are getting an error, please paste your code and error.

Walter Roberson
Walter Roberson on 10 Aug 2020
Your .mat file has two variables that are completely different. Although it is possible in theory to put both variables into the same sheet of the same .xlsx file, it would make more senset to put them into different sheets of the same file.
Your .mat file has a variable named ROI that is a cell array, each entry of which contains a struct. .xlsx files cannot contain struct entries, so you will need to transform that to some other format. Fortunately you can use
T = struct2table(cell2mat(ROI));
which will create a 36 x 4 table with fields Xaddress Yaddress Polarity TimeStamp
However, each table entry is a vector of values, with different sizes for the different rows:
Xaddress Yaddress Polarity TimeStamp
________________ ________________ ________________ ________________
{1×14813 double} {1×14813 double} {1×14813 double} {1×14813 double}
{1×11357 double} {1×11357 double} {1×11357 double} {1×11357 double}
{1×10979 double} {1×10979 double} {1×10979 double} {1×10979 double}
and so on.
In order to write that out to a single sheet of a single file, you will have to take one of a couple of tactics:
  1. You could find the longest array (28316) and pad everything to that long, then split into separate columns, and write that out, so each row would contain 28316*4 = 113264 columns. However you said you wanted a .xls file, and .xls files are limited to 256 columns; .xlsx files are limited to 16384 columns. So you would have to switch to .csv and never read the file into Excel because it would have too many columns; Or
  2. You could concatenate everything in one variable into a continuous column, 516403 rows. However, that would exceed the 65536 row limit of .xls files so you would not be able to use .xls files. It would fit into .xlsx limits. But you would need to decide how you wanted to mark which row belonged to which variable.
... Or you could instead write every cell entry into a different worksheet. As the longest one is 28316 entries, that would fit even for .xls files.

Community Treasure Hunt

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

Start Hunting!