필터 지우기
필터 지우기

How to convert this .mat file to .xls or.dat file?

조회 수: 28 (최근 30일)
Bajdar Nour
Bajdar Nour 2018년 8월 23일
댓글: Bajdar Nour 2018년 8월 23일
here is my dataset of a 3X2 array

채택된 답변

Stephen23
Stephen23 2018년 8월 23일
편집: Stephen23 2018년 8월 23일
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
  댓글 수: 3
Stephen23
Stephen23 2018년 8월 23일
편집: Stephen23 2018년 8월 23일
This converts the cell array of numeric vectors to a 6x9 numeric matrix:
M = vertcat(S.feature_vec{:});
Bajdar Nour
Bajdar Nour 2018년 8월 23일
Thanks I got it

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

KALYAN ACHARJYA
KALYAN ACHARJYA 2018년 8월 23일
편집: KALYAN ACHARJYA 2018년 8월 23일
%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
Such questions answer is already available in forum here
  댓글 수: 2
Bajdar Nour
Bajdar Nour 2018년 8월 23일
편집: Bajdar Nour 2018년 8월 23일
Thank u @ KALYAN ACHARJYA for reply and help..but the file gives me
Error using xlswrite (line 165)
Input data must be a numeric, cell, or logical array.
Error in converts (line 5)
xlswrite('mat_2_excel.xlsx',mat_file.(f{i}),f{i})
Stephen23
Stephen23 2018년 8월 23일
편집: Stephen23 2018년 8월 23일
@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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by