Convert .mat file into .xls file
81 次查看(过去 30 天)
显示 更早的评论
Hi,
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 个评论
Sulaymon Eshkabilov
2020-8-10
Hi Amit,
This is how you can write your *.mat file data into *.xlsx file:
clearvars
load('TestingTDStatic1.mat')
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);
end
回答(2 个)
Sudheer Bhimireddy
2020-8-10
Follow the example given on that page. If you are getting an error, please paste your code and error.
0 个评论
Walter Roberson
2020-8-10
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:
- 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
- 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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!