how can i put value of cell in vector?

2 Ansichten (letzte 30 Tage)
Mira le
Mira le am 8 Nov. 2019
Kommentiert: Star Strider am 8 Nov. 2019
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');

Akzeptierte Antwort

Star Strider
Star Strider am 8 Nov. 2019
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 Kommentare
Mira le
Mira le am 8 Nov. 2019
It doesn't work, the error still appear
Star Strider
Star Strider am 8 Nov. 2019
The code you posted runs without error in R2019b, as does the code I posted.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Cell Arrays finden Sie in Help Center und File Exchange

Produkte


Version

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by