how can i put value of cell in vector?

2 次查看(过去 30 天)
this error appear during the run of my program
"Cell contents reference from a non-cell array object."cell
U=[ ]
S={1 ,2 ,3}
for i=1:numel(S)
U=[U S{i}];
end
U = unique(U,'first');

采纳的回答

Star Strider
Star Strider 2019-11-8
Two options that come quickly to mind:
S={1 ,2 ,3};
U = [S{:}]
U = cell2mat(S)
Obviously these only work if the cell contents can be appropriately concatenated. If they cannot be, it is best to leave the cell array as a cell array, and address its contents as needed.
  2 个评论
Mira le
Mira le 2019-11-8
It doesn't work, the error still appear
Star Strider
Star Strider 2019-11-8
The code you posted runs without error in R2019b, as does the code I posted.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Cell Arrays 的更多信息

标签

产品


版本

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by