Remove Curly brackets from string/array - what am I working with?

I have acutally no clue what I am working with.
I got tables containing i.e. the following:
'[[0, 145, 0], [145, 169, 1], [169, 1693, 3], [1693, 1708, 1], [1708, 2729, 3], [2729, 2779, 0]]'
when I paste it in the cmd-window it looks like that:
{'[[0, 145, 0], [145, 169, 1], [169, 1693, 3], [1693, 1708, 1], [1708, 2729, 3], [2729, 2779, 0]]'}
I actually would like to access the numerical values, but don't know how - can I somehow remove those brackets and then access them?
Thanks for your help!

2 comentarios

We have no clue what you're dealing with either. It looks like a character array, not a table. Not sure exactly what you're pasting into the command window either but it looks like it might be a cell because it puts braces around it. Let us help you by attaching your variable in a .mat file
save('answers.mat', 'YourVariable');
with the paperclip icon after you read this link.
Lukas Netzer
Lukas Netzer el 6 de Ag. de 2021
Editada: Lukas Netzer el 6 de Ag. de 2021
thank you for your comment - I am working on my master thesis and never had a matlab course before - I'm not a mathematican nor am I a programmer - I am really just learning by doing, but obviously struggling.
it looks like that:
part of the data is attached - hope this works!
best regards,
Lukas

Iniciar sesión para comentar.

Respuestas (1)

Your data seems to be a cell containing JSON data:
data={'[[0, 145, 0], [145, 169, 1], [169, 1693, 3], [1693, 1708, 1], [1708, 2729, 3], [2729, 2779, 0]]'};
jsondecode(data{1})
ans = 6×3
0 145 0 145 169 1 169 1693 3 1693 1708 1 1708 2729 3 2729 2779 0

4 comentarios

Thanks for your answer - unfortunately the data is presented in a table.
In my case the table is called 'example', and the column is called 'wc'.
I tried the following:
jsondecode(example.wc(2){1}) %for row 2
which gives me
Error: Invalid array indexing.
If I try to convert all rows in the table by just:
jsondecode(example.wc{1})
I get:
Cell contents reference from a non-cell array object.
Am I missing something? thanks for your help!
edit.: it appears to be a categorical array, if that's of any help
Stephen23
Stephen23 el 5 de Ag. de 2021
Editada: Stephen23 el 5 de Ag. de 2021
"Am I missing something?"
Yes: not uploading the data so that someone here can accurately identify it.
Save it in a .mat file, then click the paperclip button to upload it here.
@Lukas Netzer: was the data provided to you in a .mat file? If not, please upload the original data file.

Iniciar sesión para comentar.

Categorías

Productos

Versión

R2021a

Preguntada:

el 5 de Ag. de 2021

Comentada:

el 6 de Ag. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by