Transform content of cell array to strings
显示 更早的评论
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
采纳的回答
更多回答(1 个)
Robert
2016-7-20
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.
类别
在 帮助中心 和 File Exchange 中查找有关 Cell Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!