Trying to export data from .mat file to excel

2 ビュー (過去 30 日間)
Faisal
Faisal 2023 年 1 月 30 日
コメント済み: Aritra 2023 年 1 月 31 日
Greetings all,
I have a large data set in .mat file (18 columns and more then 4 million rows), the data consists of numbers, dates, characters and NaN cells,
my code is as follows,
data=load('rtd.mat');
fn=fieldnames(data); %get all variable names
assert(numel(fn)==1); %assert there is only one variable in your mat, otherwise raise error
firstdiff = data.(fn{1}); %get the first variable
xlswrite('File.xlsx', firstdiff); %write it%Z
i get an error of
(Error using xlswrite (line 170)
Input data must be a numeric, cell, or logical array.)
Appreciate your support
  1 件のコメント
Murugan C
Murugan C 2023 年 1 月 30 日
please upload your mat file.

サインインしてコメントする。

回答 (1 件)

Aritra
Aritra 2023 年 1 月 30 日
Hi,
As per my understanding you are trying to export the data from a .mat file to an excel. However, the .mat file contains fields with ‘NAN’ values which results in the following error:
(Error using xlswrite (line 170)
Input data must be a numeric, cell, or logical array.)
Excel fails to interpret the NaNs in a numberic matrix.
To write a matrix with NaNs to an Excel file, the NaN values must be explicitly written as strings like 'NaN'. To achieve the same, you can convert your data matrix to a cell and replace all NaNs with 'NaN' before writing to Excel as shown below:
A = load(<filename.mat>);
B = num2cell(A);
B(isnan(A)) ={'NaN'};
xlswrite(filename,B);
  2 件のコメント
Faisal
Faisal 2023 年 1 月 31 日
Thank you Arita,
I tried to use the same code that you wrote, however, the error below pops up
Check for incorrect argument data type or missing argument in call to function 'isnan'.
Appreciate your support
Aritra
Aritra 2023 年 1 月 31 日
Can you please share your .mat file?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by