How to combine cells into a single cell?

How to pass from "a" to "b", here following?
a = [{'[1,2)'}, {'[2,6)'},{'[6,11)'}]; % input
b = {'[1,2)','[2,6)','[6,11)'}; % desired output
I tried cat, but, it does not work:
b = cat(1,a{:})
Error using cat
Dimensions of arrays being concatenated are not consistent.

 Accepted Answer

b = a;

4 Comments

a and b are already the same
a = [{'[1,2)'}, {'[2,6)'},{'[6,11)'}]; % input
b = {'[1,2)','[2,6)','[6,11)'}; % desired output
isequal(a,b)
ans = logical
1
a = [{'[1,2)'}, {'[2,6)'},{'[6,11)'}]; % input
If you want a single character vector:
b = cat(2,a{:})
b = '[1,2)[2,6)[6,11)'
Or if you want a scalar cell array containing that character vector:
b = {cat(2,a{:})}
b = 1x1 cell array
{'[1,2)[2,6)[6,11)'}
You're welcome!

Sign in to comment.

More Answers (0)

Asked:

Sim
on 21 May 2024

Commented:

on 21 May 2024

Community Treasure Hunt

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

Start Hunting!