How to build a num array
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Andreas Fröhlich
il 1 Feb 2021
Risposto: Walter Roberson
il 1 Feb 2021
Hello,
I have following situation, from a database I got following table:
table (1,1) = {'[-7.045866760858189, -6.961728203539678, -6.378816032116447]'}
How can I create a num table with a array of each value?
Tablenew (1,1) = -7.045866760858189
Tablenew (1,2) = -6.961728203539678
...
0 Commenti
Risposta accettata
Walter Roberson
il 1 Feb 2021
The below solution assumes that there are the same number of entries in each row, but does not depend upon there being exactly 3.
format long g
Table(:,1) = {'[-7.045866760858189, -6.961728203539678, -6.378816032116447]';
'[-3.13423, -5.5512435, -99.999999999]'}
Tablenew = cell2mat(cellfun(@str2num, Table(:,1), 'uniform', 0))
Tthe str2num() will eval() each line, and if a line happened to contain something like 'rmdir(".")' then it would be happy to delete your directory.
The below solution assumes that there are exactly 3. It is a more secure solution. It could be generalized with not a lot work for the case where the number per line was consistent but not necessarily 3.
cell2mat(textscan(strjoin(Table(:,1)), '[%f,%f,%f]'))
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Tables in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!