Hi,
I'm trying to export a matrix called xyzCGAT into Excel (three columns and 60480000 rows for each column). I've tried using xlswrite (code below) and it produces the error:
Error using xlswrite (line 172)
Input data must be a numeric, cell, or logical array.
Error in conversion_to_excel (line 5)
xlswrite(filename,A);
The values within the matrix are acceleration values and some are negative so therefore include a minus symbol infront of the value. Is this causing the issue?
Any advice about where I'm going wrong or how to convert such values to an Excel file would be really appreciated. Thanks in advance!
load xyzCGAT.mat
A = table (1,2,3)
A(:,1:3)
filename= 'xyzCGAT.xlsx'
xlswrite(filename,A);

 Akzeptierte Antwort

Jesus Sanchez
Jesus Sanchez am 19 Feb. 2019
Bearbeitet: Jesus Sanchez am 19 Feb. 2019

0 Stimmen

xlswrite only works with matrixes and you created a table. You are looking for the function called "writetable"
PS: As you are working with tables, it is possible to call each row of the table with a name, which later on will also be saved to the excel file, txt file or whichever you want. In the link provided above there are good examples of that.
EDIT: An example in your code:
writetable(A,filename);

8 Kommentare

Rebecca Hadley
Rebecca Hadley am 19 Feb. 2019
Thank you, I'll give this a try. I have the data stored as a matrix so I could use xlswrite I guess based from what you've said?
Jesus Sanchez
Jesus Sanchez am 19 Feb. 2019
Bearbeitet: Jesus Sanchez am 19 Feb. 2019
Indeed, if your data is stored in a matrix, you should be able to use xlswrite without problems. However, in your code you wrote:
A = table (1,2,3)
This defines A as a "table" and therefore it has to be treated as one. If you change your code so A is a matrix, there should be no problems.
Rebecca Hadley
Rebecca Hadley am 20 Feb. 2019
Would this work using a pre-saved matrix? I can't work out how to code to define A as the pre-saved matrix 'xyzCGAT.mat'. All the examples for using xlswrite seem to indicate that you have to define A as elements of a matrix. I hope this makes sense.
Jesus Sanchez
Jesus Sanchez am 20 Feb. 2019
As far as I know, you need to load the pre-saved matrix in the workspace.
Lets say that the matrix saved in 'xyzCGAT.mat' is called A. Just do:
load 'xyzCGAT.mat' % Load matrix.
Then, in your workspace you will see a new variable called A, or whichever name the variables inside 'xyzCGAT.mat' are. Now you can save it using the preivous code.
Sorry, yesterday the site seemed to be having technical issues so I couldn't respond to your answer. Thank you so much for your help. I tried your suggestion, but because I'm not great at writing code (I understood what you meant, but implementing it is somwhat tricky for me), I ended up using a different code (see below). This sort of worked, although it writes it into csv not xlsx.
data=load(filename);
f=fieldnames(data);
for k=1:size(f,1)
xlswrite(filename.xlsx,data.(f{k}),f{k})
end
Jesus Sanchez
Jesus Sanchez am 23 Feb. 2019
Bearbeitet: Jesus Sanchez am 23 Feb. 2019
Thank you for your update. Just one thing. In your code, you just add a .xlsx for the filename name in xlswrite. This is probably the reason why it is being saved as a .cvs.
- Matlab asks specifically for a char as an input. Therefore, instead of
xlswrite(filename.xlsx,data.(f{k}),f{k})
I would try with
xlswrite(char(strcat(filename,'.xlsx')),data.(f{k}),f{k})
it is a little bit tricky, but it should save the result in .xlsx files now.
  • strcat creates a unique string adding filename and .xlsx
  • char converts the resulting string to char format.
I hope this works :)
Rebecca Hadley
Rebecca Hadley am 3 Mär. 2019
Hi,
Thanks for the additional advice! I tried to give it a try on a different computer and I got the following error (unrelated to the actual code I believe):
Out of memory. Type HELP MEMORY for your options.
I tried using the memory function and got the following information:
Maximum possible array: 26643 MB (2.794e+10 bytes) *
Memory available for all arrays: 26643 MB (2.794e+10 bytes) *
Memory used by MATLAB: 2964 MB (3.108e+09 bytes)
Physical Memory (RAM): 8103 MB (8.497e+09 bytes)
Is anyone able to help me interpret what it is telling me?
Jesus Sanchez
Jesus Sanchez am 4 Mär. 2019
Hello,
please create a new and separate topic for this. I am not sure of that error and, as this is a question that already has an answer, it will not appear for that many people

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte

Version

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by