Cell Array to table

8 ビュー (過去 30 日間)
Alberto Lorenzo
Alberto Lorenzo 2019 年 2 月 22 日
回答済み: Peter Perkins 2019 年 2 月 25 日
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:
Capture.PNG

採用された回答

Peter Perkins
Peter Perkins 2019 年 2 月 25 日
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).

その他の回答 (1 件)

madhan ravi
madhan ravi 2019 年 2 月 22 日
doc cell2table
  1 件のコメント
madhan ravi
madhan ravi 2019 年 2 月 22 日
T=cell2table(Values);
T.Properties.VariableNames={'id','factor','position','pts','Pt_Location','Turn_Rate','ST_Location','speed'}

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by