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!