# Problem 1899. Convert a Cell Array into an Array

2 visualizaciones (últimos 30 días)
Mayla el 19 de Sept. de 2023
Given a square cell array:
x = {'01', '56'; '234', '789'};
return a single character array:
y = '0123456789'
I wrote a code that passes Test 1 and 2 and one that passes Test 3 but I'm searching a condition so that the code for Test 3 runs when the cell array only contains letters and the one for Test 1 and 2 in every other case. Can somebody help me?
This is my code:
y = []
[a,b]=size(x)
%%TEST 3
delimiter=zeros(1,a)
delimiter(end)=1
delimiter=repmat(delimiter,1,b)
delimiter(end)=''
delimiter=string(delimiter)
y=[]
for i=1:a*b
y = string([y x(i)])
end
y=join(y,delimiter)
y=erase(y,'0')
y=regexprep(y,'1',' ')
%%TEST 1+2
for i=1:a*b
y = string([y x(i)])
y=join(y)
end
y=erase(y,' ' )
##### 5 comentariosMostrar 3 comentarios más antiguosOcultar 3 comentarios más antiguos
Dyuman Joshi el 19 de Sept. de 2023
Adam Danz el 19 de Sept. de 2023
I didn't want to give away a cody solution ;)

Iniciar sesión para comentar.

Matt J el 19 de Sept. de 2023
Editada: Matt J el 19 de Sept. de 2023
x = {'01', '56'; '234', '789'};
y=[x{:}]
y = '0123456789'
x={'' 'a' '1'; 'AA' 'BB' 'CC'; 'dog' 'cat' 'car'};
y=[x{:}]
x={'We' 'do' ;'ll ' 'ne.'};
y=[x{:}]
y = 'Well done.'
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Categorías

Más información sobre Function-Based Unit Tests en Help Center y File Exchange.

### Community Treasure Hunt

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

Start Hunting!

Translated by