want to convert cell to matrix

4 views (last 30 days)
bilhan
bilhan on 18 May 2011
see i have a cell A={[1 2] [3 4] [5 6]..........} i want the output as b1=[1 2] b2=[3 4] b3=[5 6] .......... i want the content of the each element in the cell to be represeted as different matrices.

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 18 May 2011
variant
for j = 1:length(A)
k = num2str(j);
eval(['b' k '=A{' k '}']);
end
or
[b1,b2,b3,...,bN] = A{:};
  2 Comments
bilhan
bilhan on 18 May 2011
thank you mr.bobrov
Jan
Jan on 18 May 2011
I strongly recommend the non-EVAL method.
But see: http://matlab.wikia.com/wiki/FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F It is usually *much* more efficient to use one array and indexing instead of a pile of variables. Therefore I suggest using CELL2MAT, or cat(2, A{:}).

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!