jdl
jdl

Reputation: 6323

matlab: I want to convert a cellarray to an array?

Conversion?

array(1:3) = cellArray{1:3}; 
% this fails:  "Subscripted assignment dimension mismatch."

note: I know how to do this in a loop. Looking for matlab direct route.

%% Contents of cellArray %%

K>> cellArray{1:3}

ans =

11


ans =

f0


ans =

05

Upvotes: 0

Views: 51

Answers (2)

Shai
Shai

Reputation: 114816

If all cells are of the same type, and share similar first dimension, then

array = [cellArray{:}];

should work

Upvotes: 1

shoelzer
shoelzer

Reputation: 10708

Use cell2mat.

A = cell2mat(C) converts cell array C with contents of the same data type into a single array, A.

Upvotes: 2

Related Questions