MATLAB Answers

Cell to mat conversion

47 views (last 30 days)
Hi,
I have a cell array and need to convert to array.
a = {[100, 200, 300, 400, 500], [1000, 2000, 3000, 4000, 5000], [1100,1200, 1300, 1400, 1500]};
for each set b = a(1);
I need array data like,
b = [100, 200, 300, 400, 500];
i tired cell to mat, its not working.

Accepted Answer

Bjorn Gustavsson
Bjorn Gustavsson on 24 Feb 2021
If you want to extract the content of one cell simply do:
b = a{1};
If you want to merge a couple of cells into an array or matrix you can do:
B2 = cell2mat(a([1 3]));
B3 = cell2mat(a([1,3])');
HTH
  7 Comments
Chandan Prakash
Chandan Prakash on 24 Feb 2021
OK, thank you for good explanation.

Sign in to comment.

More Answers (1)

KSSV
KSSV on 24 Feb 2021
Edited: KSSV on 24 Feb 2021
iwant = reshape(cell2mat(a),[],length(a))' ;
iwant(1,:)
  3 Comments
Chandan Prakash
Chandan Prakash on 24 Feb 2021
Hi,
Yeah i tired the way you suggested it works,
but for the data i have i'm getting result as char array in a single cell.
Thank you.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by