Please help me out in a detail manner xlswrite command is not working

8 Kommentare

Jürgen
Jürgen am 31 Aug. 2012
please show the code that you already tried?
PRABHU SRINIVASAN
PRABHU SRINIVASAN am 1 Mär. 2017
Hi I tried to convert my .mat data to .xls but unable to do it. The .mat file data struct contains huge amount of data i.e the 107968x1 for all the variables. I want to convert it to a .xls can anyone give idea in this regard.
Walter Roberson
Walter Roberson am 1 Mär. 2017
Xls files are limited to 65535 rows. If you managed to create a file that big then Excel itself would be unable to read it.
You will need to use xlsx
PRABHU SRINIVASAN
PRABHU SRINIVASAN am 2 Mär. 2017
Can i export my .mat file data to xlsx? Is there any procedure for doing with matlab code? Please advise...
Walter Roberson
Walter Roberson am 2 Mär. 2017
xlswrite() can write .xlsx files.
If your data is in the form of a table() or timetable() object, then writetable() can write it to .xlsx
Christine  Zarief
Christine Zarief am 10 Mär. 2018
Bearbeitet: Walter Roberson am 28 Mär. 2018
I have an error for converting .mat files into .xlsx files ,I used this code
load('train_subject01.mat')
xlswrite('kokytest.xlsx', train_subject01)
and matlab gives me this error message
Undefined function or variable 'train_subject01'.
so please could anyone help me to solve it ?
Thanks in advance
Your .mat file train_subject01.mat did not contain a variable named train_subject01 . You should use
whos -file train_subject01.mat
to see the names of the variables in the file.
Zhibo
Zhibo am 2 Aug. 2022
我做了一个matToExcel工具可以在线处理这个问题

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 31 Aug. 2012

14 Stimmen

data=load('FileName');
f=fieldnames(data);
for k=1:size(f,1)
xlswrite('FileName.xlsx',data.(f{k}),f{k})
end

15 Kommentare

Farhan
Farhan am 31 Aug. 2012
Thanks for your reply Actually the problem is in my mat file i have many date types like CELL, Structure,character etc.
Image Analyst
Image Analyst am 31 Aug. 2012
Doesn't matter. Just make up one big cell array with all your various variables in it, and pass it to xlswrite().
Albert Yam
Albert Yam am 31 Aug. 2012
Should still work, Azzi's answer puts everything on it's own sheet.
If you know how you want your excel to look, format into a giant cell (per sheet), ala Image Analyst's answer.
akrim
akrim am 12 Sep. 2013
thank you, i have a same problem and this work for me.
ElizabethR
ElizabethR am 21 Apr. 2016
i also have the same problem and now it has been solved. thanks!
shilpa gangarudraiah
shilpa gangarudraiah am 28 Mär. 2018
Thankyou ...
Yassin Mounir
Yassin Mounir am 7 Apr. 2018
Thank you the mat file successfully saved as excel sheet
Heera R Nair
Heera R Nair am 2 Dez. 2018
Thank you so much. It worked
jd net
jd net am 20 Feb. 2019
guddddddddddd
Rebecca Hadley
Rebecca Hadley am 23 Feb. 2019
Hi,
I used the code provided by Azzi to write a .mat file to .xlsx, but halfway through Matlab provides a warning saying that it will use writecsv instead. To quicken the process, I tried changing the xlswrite to csvwrite (perhaps naively so) and Matlab keeps coming up with the error: 'not a valid attribute or row offset'. What would be the best way to use csvwrite with a pre saved .mat file?
Hakeem Niyas
Hakeem Niyas am 3 Jan. 2020
I am getting the below error
Error using xlswrite (line 170)
Input data must be a numeric, cell, or a logical array
Walter Roberson
Walter Roberson am 3 Jan. 2020
When you see a warning that writecsv will be used instead, then you know that either you are not using MS Windows, or else you are using MS Windows but Excel cannot be found. In such a case you should switch to using writetable() instead if possible.
Walter Roberson
Walter Roberson am 3 Jan. 2020
xlswrite() cannot be used to write variables of arbitrary datatype to xls or xlsx files. It can only be used to write numeric arrays, or logical arrays, or cell arrays in which each entry is a numeric value, or a logical value, or a character vector (or, these days, a string() scalar).
writetable() can handle some additional datatypes, but some datatypes it will simply leave empty cells for. For example, it will leave empty cells for Control System Toolbox transfer functions, or for symbolic expressions.
Anthony Santana
Anthony Santana am 5 Nov. 2021
Hi,
I am trying to convert an output mat file which contains 1.5MM rows of numbers to an excel file.Smeone suggested I change it from 3D to 2D first. I tried the following codes and nothing works. Can you fix it?
S=load('QQ_full.mat');
data=S.QQ;
data=reshape(data,size(data,1)*size(data,2),size(data,3));
writetable(S.QQ,data,'Sheet',1,'Range','A1')
Error using writetable (line 248)
Unsupported type 'double'. Use writematrix instead.
Did you mean:
>> writematrix(S.QQ,data,'Sheet',1,'Range','A1')
Error using matlab.io.xml.internal.write.errorIfXML (line 6)
FILENAME must be a non-empty character vector or string scalar.
Error in writematrix (line 196)
fileType = matlab.io.xml.internal.write.errorIfXML(filename, supportedFileTypes, varargin{:});
Walter Roberson
Walter Roberson am 5 Nov. 2021
Bearbeitet: Walter Roberson am 5 Nov. 2021
S=load('QQ_full.mat');
data=S.QQ;
Okay, at that point S.QQ and data are the same.
data=reshape(data,size(data,1)*size(data,2),size(data,3));
and data gets reshaped so S.QQ and data now have the same content but different shape.
writematrix(S.QQ,data,'Sheet',1,'Range','A1')
You are asking to write out S.QQ, which is the original shape, and you are asking that it be written to a file whos name is stored in data .
You should be using something like
writematrix(data, 'Q_reshaped.xlsx', 'Sheet', 1, 'Range', 'A1')
However...
I am trying to convert an output mat file which contains 1.5MM rows of numbers to an excel file.
You have a problem. The largest file that excel supports is 1048576 rows, and you are creating more rows when you reshape.
The maximum number of columns for excel is 16384, so you would need to use permute() and reshape() to re-arrange your data to have fewer rows but more columns, but still fit within the 2^20 x 2^14 = 2^34 element = 16 giga-element (powers-of-two meaning of "giga" here). If numel(s.QQ) > 2^34 then you have no hope of fitting it into a single excel sheet.
You might want to write sections to different sheets.
What is size(S.QQ) ?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

kinju Prajapati
kinju Prajapati am 11 Jan. 2019

0 Stimmen

how to load my own datset for training and testing....
nprtool only respond inbuilt or example dataset..not my dataset,,,,

4 Kommentare

Walter Roberson
Walter Roberson am 3 Jan. 2020
How are your datasets represented? nprtool permits you to indicate which variable to use, or if you use the '...' button to the right of that, you can select a text file or .mat file to read data from.
arun anoop m
arun anoop m am 27 Jul. 2020
This code working fine(mat to xls).
Abhishek
Abhishek am 6 Apr. 2023
Bearbeitet: Abhishek am 6 Apr. 2023
Hi @arun anoop m, can you show me how to transfer all data dictionary data to excel ?
Walter Roberson
Walter Roberson am 6 Apr. 2023
I am not clear whether you are referring to a Simulink Data Dictionary https://www.mathworks.com/help/simulink/slref/simulink.data.dictionary.html or if you are referring to the releative new dictionary mapping object?

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by