How to convert this .mat file to .xls or.dat file?
116 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Bajdar Nour
am 23 Aug. 2018
Kommentiert: Bajdar Nour
am 23 Aug. 2018
here is my dataset of a 3X2 array
0 Kommentare
Akzeptierte Antwort
Stephen23
am 23 Aug. 2018
Bearbeitet: Stephen23
am 23 Aug. 2018
Your .mat file contains a 3x2 cell array, each cell of which contains a 1x9 numeric array: this data cannot be saved in a 2D array file format such as a text file or an Excel file. To save in a 2D array file format (i.e. a text file or Excel file) you will need to have a cell array containing scalar values, or use a numeric array, or use some format that encodes nested data (this is not trivial). Here I used cell2mat to form one 3x18 numeric array, which can easily be saved in a text file or an Excel file:
>> S = load('20-8-2018.mat');
>> M = cell2mat(S.feature_vec);
>> csvwrite('output.dat',M) % to make a text file
>> xlswrite('output.xls',M) % to make an Excel file
Weitere Antworten (1)
KALYAN ACHARJYA
am 23 Aug. 2018
Bearbeitet: KALYAN ACHARJYA
am 23 Aug. 2018
%Rename the mat file to some simple name say file1.mat (Not Mandatory)
mat_file=load('file1.mat');
f=fieldnames(mat_file);
for i=1:size(f,1)
xlswrite('mat_2_excel.xlsx',mat_file.(f{i}),f{i})
end
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/194115/image.png)
2 Kommentare
Stephen23
am 23 Aug. 2018
Bearbeitet: Stephen23
am 23 Aug. 2018
@Bajdar Nour: that error message is a bit misleading. The xlswrite documentation states that each cell of the cell array must contain a scalar numeric, or text. However each cell of your cell array contains a 1x9 numeric. See my answer for one solution to this.
Siehe auch
Kategorien
Mehr zu Data Type Identification finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!