Parsing table of string without looping
Show older comments
Hello,
I have a table of string (name : polystring 300 000 x 1 table) where each string register a set of gps coordinates that defines a polygon.
For instance, one string can be : 2.331878 48.866003, 2.331872 48.866107, 2.331855 48.866211, 2.331825 48.866314, 2.331785 48.866416, 2.331733 48.866517, 2.331669 48.866617, 2.331595 48.866715, 2.331509 48.866811
Each got a different number of points (from a few to 200 points or so).
By using this command :
B = cellfun(@(x) strsplit(x, ", ")', polystring, 'uni', false);
I managed to create an array of cells (300 000 x 1 cell) where each cell is a (N x 1 cell). Each cell is storing a string like "2.331878 48.866003"
I would like now to parse the cells to have a (300 000 x 1) with each cell being a (N x 2) matrix, by parsing my previous (N x 1) using " " as a splitter.
I do not get how I should do it as using
C = cellfun(@(x) str2double(strsplit(x, " ")), B, 'uni', false);
Trigger an error 'First input must be either a character vector or a string scalar.'
Ultimately, the aim is to create polygon (polyshape(P) with P being my Nx2 matrix of GPS coordinates)
A warm thanks for any help or hint provided
1 Comment
Guillaume
on 1 Feb 2020
Note that if the initial table of strings is the result of a text file import a much more efficient solution would be to fix the import so that it imports the data directly as a numeric array/table. To help with that, we need the details of the text file.
Accepted Answer
More Answers (0)
Categories
Find more on MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!