Cell Array to table
21 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Alberto Lorenzo
le 22 Fév 2019
Réponse apportée : Peter Perkins
le 25 Fév 2019
I have a cell array that contains elements of different sizes:
Values =
1×8 cell array
{[1]} {[0.35]} {1×3 double} {[0]} {1×2 double} {[0]} {1×2 double} {[1]}
I want to save Values, into an existing table. The table has VariableTypes set to cell.
obj.Table{i}(indx,:) = Values
Conversion to cell from double is not possible.
Table should look something like this:

0 commentaires
Réponse acceptée
Peter Perkins
le 25 Fév 2019
Alberto, you are mixing metaphors.
You have a cell array containing values you want to put in a table, and (apparently) a table that is preallocated with cell variables. It looks like what you want is a table that has double variables, some with one column, some with more than one. I'm guessing, though you haven't really given any context, that you will have many of those cell arrays, and you want to assign them one at a time into each row of the table.
You have obj.Table{i}. Again, I can only guess that obj.Table is a cell array, and obj.Table{i} is a table that's been preallocated. It would help if you would either remove the parts of your code that are irrelevant to your question, or explain the code sufficiently.
In any case: Let's say t = obj.Table{i}. t is a table, and t(indx,:) is one row of that table. To assign to that one row, you need to have a table on the right-hand side. You have a cell array. So in that sense, madhan's suggestion is correct. But table actually gives you a short-cut: you can assign a one-row cell array to a row of a table, and the table on the LHS behaves "as if" you had already called cell2table. It's a convenience to save you some typing, and some execution time.
But the target has to be variables that are the right types. You say, "variable types set to cell", and there's your problem. You are, as the error msg says, trying to assign double values into cell arrays. Preallocate with double (and the right number of columns for each).
0 commentaires
Plus de réponses (1)
madhan ravi
le 22 Fév 2019
doc cell2table
1 commentaire
madhan ravi
le 22 Fév 2019
T=cell2table(Values);
T.Properties.VariableNames={'id','factor','position','pts','Pt_Location','Turn_Rate','ST_Location','speed'}
Voir également
Catégories
En savoir plus sur Matrices and Arrays dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!