cell2table not recognizing cell array

I am attempting to convert a cell array to a table and then save it as an excel file.
Cell_Array = handles.caIGLs;
i = 1 : numel(Cell_Array);
T = cell2Table(Cell_Array);
Name = 'testdata.xlsx';
XLDoc = xlswrite(Name, T);
Folder = 'C:\Users\c13459232\Documents\MATLAB\Completed code thus far\Results';
file = XLDoc;
save(fullfile(Folder, Name), file);
Using this method, the error that occurs is: Undefined function 'cell2Table' for input arguments of type 'cell'.
Using cell2Table(Cell_Array(i)) the error is: Undefined function 'cell2table' for input arguments of type 'cell'.
Using cell2table(Cell_Array{i}) the error is: Undefined function 'cell2table' for input arguments of type 'double'.
Why is the cell2table function failing to recognize cells as an input?

Risposte (1)

Jan
Jan il 9 Ago 2017
Modificato: Jan il 9 Ago 2017
Matlab is case-sensitive. Some of the error messages contain an upper-case "T" in "cell2Table". Note that the error message does not mean that "cell2table function failing to recognize cells as an input".
Try:
cell2table(Cell_Array)
If this does not word, which Matlab version are you running? Note that this function was introduced in 2013b.

10 Commenti

I'm using 2012. Is there another way, other than cell2table that this action can be carried out? Using the table command?
Stephen23
Stephen23 il 10 Ago 2017
Modificato: Stephen23 il 10 Ago 2017
@Aaron Smith: tables were introduced in R2013b:
The online help is fun to play with, but the only help documentation you should rely on is the help that is part of your installed MATLAB.
In any case it is not required to convert a cell array to a table before saving the data to an excel workbook. Why do you want to perform this step?
Adam
Adam il 10 Ago 2017
Modificato: Adam il 10 Ago 2017
You should get used to using the help installed with your version of Matlab ahead of online help. If you do find a solution to something online or end up in the Matlab online help then double check in your local help if the functions exist first. It saves a lot of time. The default online help is always for the latest Matlab.
Unfortunately when it comes to online solutions in fora like this there is often no information as to which version of Matlab is needed for the solution because it is not realistic in many cases. In many cases, when answering a question, people naturally use their knowledge based on whatever version of Matlab they are using. Sometimes we add a comment that the answer only works from a certain version, but often this gets forgotten. A big part of the reason for that is because probably < 1% of people asking questions give information on their Matlab version and it isn't a field to fill in for the question like tags and Products (which also people mostly ignore anyway).
I thought it was necessary. In that case then this code should suffice, right?:
xlDoc = xlswrite( name, cell array);
Folder = 'C:\Users\c13459232\Documents\MATLAB\Completed code thus far\Results';
file = XLDoc;
save(fullfile(Folder, Name), file);
Stephen23
Stephen23 il 10 Ago 2017
Modificato: Stephen23 il 10 Ago 2017
@Aaron Smith: You have been asking questions on this forum for half a year, which is enough time for you to locate and start reading the MATLAB documentation yourself. I wrote you earlier "You are wasting a lot of your own time by not reading the documentation for functions that you are using". Source:
That was not the only time that you have been advised to read the documentation:
etc, etc.
With that in mind, can you please explain what this code does?:
xlDoc = xlswrite( name, cell array);
Folder = 'C:\Users\c13459232\Documents\MATLAB\Completed code thus far\Results';
file = XLDoc;
save(fullfile(Folder, Name), file);
xlswrite creates an excel spreadsheet. I chose the arbitrary 'name' here, a real name will obviously be assigned in the actual code. The data for the spreadsheet is 'Cell Array', again an arbitrary name.
I specify the folder i want to save the data in as Folder
I assign the excel spreadsheet the name 'file'. Not really necessary as I could just pass 'xlDoc' but it was a holdover from before when I was still using cell2table.
save the excel spreadsheet in the folder 'Folder' under the title 'Name'. Again, an arbitrary title which I will set in the actual code. I read the Matlab docuemntation for xlswrite yesterday when i started using it, as I do with the documentation for any command when I start using them.
Stephen23
Stephen23 il 10 Ago 2017
Modificato: Stephen23 il 10 Ago 2017
@Aaron Smith: as you have just read the xlswrite documentation then you should be able to tell me what the purpose is in saving the status value (either 1 or 0) to another file.
The status value informs the user whether or not xlswrite has been successful. 1 for successful, 0 for unsuccessful. In my code above the variable i am saving as xlDoc is in fact the status rather than the new xl spreadsheet that is created by xlswrite as it would be with any of the other commands I've used. Simply missing that left of the equals sign is different in this case than in any of the other commands I've used down not equal not reading the documentation.
Stephen23
Stephen23 il 10 Ago 2017
Modificato: Stephen23 il 10 Ago 2017
"...rather than the new xl spreadsheet that is created by xlswrite as it would be with any of the other commands I've used"
What "other commands I've used" return the data itself after writing this data to file? Is there any MATLAB function that returns the entire data that it has just written to file? Lets have a look at the documentation for all file export functions for standard file formats:
Bonus:
Most of these functions do not have any output at all. What commands have you been using, such that "...that left of the equals sign is different in this case than in any of the other commands I've used" ?
Jan
Jan il 10 Ago 2017
Modificato: Jan il 10 Ago 2017
@Aaron Smith: If foreign people spend their spare time to solve your problem, they will expect, that you took the time to read the documentation at first. It would have been easy for you to find out, that cell2table does not exist in your Matlab version. If you had mentioned the version you are using, I wouldn't post my useless answer.
That xlswrite replies an Excel sheet is a bold speculation. Even if you believe this, you can check this very easily by running the code in the command window:
xlDoc = xlswrite( name, cell array)
You will see immediately, what the output xlDoc is, and then you should start your own investigations at first by reading the docs.
The term "write" means, that the object is written, and not replied.
Your interpretation, that the message "Undefined function 'cell2table' for input arguments of type 'cell'" means, that cell2table "is failing to recognize cells as an input", was a speculation also. This is not a reliable way to program. Read the messages and the docs carefully. Consider, that your local documentation concerns the version, you have installed. Read th online docs to learn something about the current version, consider the "introduced in" information at the bottom. Do not guess, what functions reply, but trust the docs only.
I agree with Stephen. But even if I suggest to improve your programming skills, it is clear that questions about Matlab are welcome in this forum. Your questions can be more efficient and you can invest more effort before, but it is the decision of the ones who answer, if they want to spend their time. So let this encourage you to use the forum more efficiently. Okay?
Create an Excel file:
Folder = 'C:\Users\c13459232\Documents\MATLAB\Completed code thus far\Results';
xlswrite(fullfile(Folder, Name), CellArray);

Accedi per commentare.

Prodotti

Richiesto:

il 9 Ago 2017

Modificato:

Jan
il 10 Ago 2017

Community Treasure Hunt

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

Start Hunting!

Translated by