Storing integers from a cell in a variable

3 visualizaciones (últimos 30 días)
Hello all,
I have a 63x1 cell and its contents basically look as shown below
'(4,4)'
'(3,4)'
'(2,4)'
'(1,4)'
'(0,4)'
'(-1,4)'
'(-2,4)'
I would like Matlab to the pick the integers from each cell and store it in different variables. For example, x should contain [4 3 2 1 0 -1 -2] and Y should contain [4 4 4 4 4 4 4 ].
I would be grateful if someone can help me with this.
Thanks in advance
Best Regards,
Bala

Respuesta aceptada

Stephen23
Stephen23 el 22 de Jul. de 2020
Editada: Stephen23 el 22 de Jul. de 2020
Much more efficient than cellfun:
>> C = {'(4,4)';'(3,4)';'(2,4)';'(1,4)';'(0,4)';'(-1,4)';'(-2,4)'};
>> V = sscanf([C{:}],'(%f,%f)');
>> X = V(1:2:end)
X =
4
3
2
1
0
-1
-2
>> Y = V(2:2:end)
Y =
4
4
4
4
4
4
4
  1 comentario
Balasubramanian Sundarapandian
Balasubramanian Sundarapandian el 23 de Jul. de 2020
Thanks a lot for such a quick response! It works like a charm! Was a great help.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Testing Frameworks en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by