Transform content of cell array to strings
Show older comments
Hi,
I am importing some data, amongst other coordinate points (Lon/Lat), from a xlsx file using readtable. I then use table2array on some columns in order to get rid off the "table type" and be able to use the data for further analysis. The table2array transformation produces a 289x1 cell. Each cell contains only one line such as e.g.: 013° 39.541'E
This coordinate point I want to transform from degrees, minutes to a decimal coordinate using
LonHHMM = sscanf(CheckS, '%d %*s %f');
LonDeg = LonHHMM(1)+LonHHMM(2)/60;
The problem I am having is that I do not know how to extract the content of each cell as string. I do know that for a single cell I can use
CheckS = CPLon{1};
and then the above code to decimal format works fine. But how can I do this for all 289 cells? I tried using cellfun but I dont know what the first argument (@???) should look like. Or do I need to use a for loop in this case?
Your help is highly appreciated. Thanks in advance!
Oliver
Accepted Answer
More Answers (1)
Robert
on 20 Jul 2016
If all the lines of your data take the format of your example line, you could use
x = regexp(myCellArray,'([\d.]*)','match')
x = vertcat(x{:})
x = str2double(x)
to extract the numeric values of your strings.
Then, if your coordinates aren't all East, you will need to grab the direction and apply that to your data as required by your application. You could try
directions = cellfun(@(s)s(end),myCellArray)
If you are able to provide an example (small-ish) data set, we might be able to determine a cleaner way to load your data from the table.
Categories
Find more on Cell Arrays 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!