Kumud Alok
Kumud Alok

Reputation: 23

how to convert mat file into xlsx file

After executing code, I received an error:

 load('firstdiff.mat')
 xlswrite('test.xlsx', firstdiff)

mat file consist only numeric values (0 and 1)

Undefined function or variable 'firstdiff'

Upvotes: 0

Views: 17921

Answers (1)

Daniel
Daniel

Reputation: 36710

Using load without output arguments is something which often confuses programmers. I recommend to use it with an output argument:

data=load('firstdiff.mat')

This way you get a struct containing the data of your mat file. A typical next step would be using fieldnames(data) to check which variables are present or if you already know, index a variable with an expression like data.x

In this case I assume you only have one variable in your matfile.

data=load('firstdiff.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('test.xlsx', firstdiff); %write it

Upvotes: 1

Related Questions