Convert from cell of a table to an array

2 views (last 30 days)
I am importing data from an excel spreadsheet as follows:
options = readtable('options.xlsx');
Some of the excel cells contain descitions of arrays like "[1,2,3]". The cell from readtable would then be:
I would like to convert this to an array of doubles like
How can I go about doing this?

Accepted Answer

Sindar on 30 Oct 2020
Edited: Sindar on 30 Oct 2020
It gets tricky with different variable types and widths, but hopefully this helps. Worst case, you build up the new table element by element:
% build example like your table
t =
1×2 table
Var1 Var2
___________ ___________
{'[1,2,3]'} {'[4,5,6,7]'}
% start a new table
% convert the text in the cell to an array:
t2 =
1×2 table
Var1 Var2
___________ ________________
1 2 3 4 5 6 7
Cameron Dyson
Cameron Dyson on 30 Oct 2020
Thank you, its working for me now!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!