convert char to double
显示 更早的评论
I really appreciate someone tell me how can I convert attached file to double.
Thanks in advance.
采纳的回答
Farshid - try using cellfun. It seems that the pn is a cell array with 38 elements and each element is a 8x1 char array. You haven't mentioned if each of the 8 characters is a single number or if all 8 combine to one (I'll assume the latter).
>> myData = load('example.mat');
>> numericData = cellfun(@(x)str2double(x'), myData.pn);
8 个评论
Please check array 16 "numericData(16)" it is array I have problem. Please take a look at myData.pn(16).
I'm not sure what your question is? The data looks like
>> myData.pn{16}
ans =
66
99
00
11
99
65
29
That is how it is in your example.mat file. And the way I've coded this is so that this gets converted to 66990011996529. Are you expecting two numbers like 6901962 and 6901959?
Are you expecting two numbers like 6901962 and 6901959? YES, I expect to be in two different column
sigh. you can do something like
>> myData = load('example.mat');
>> numericData = cell2mat(cellfun(@(y)arrayfun(@(x)str2double(y(:,x)'),1:size(y,2))', myData.pn,'UniformOutput',false));
which works for this data set but I don't know if it will work for other sets. It uses cellfun to evaluate each cell in your myData.pn cell array. This evaluation uses arrayfun to evaluate each column in the char array - first taking the transpose of the column and then converting it to a double.
Dear Geoff,
It's working, but I want to keep a size something like 2*38. please see the form of the 'lon' attached. Since the each array of 'pn' (platform number) should be assigned to the one longitude and latitude correspondingly.
I really appreciate any comment to improve.
should be in two row exactly same form of lon and lat
Farshid - it probably would have been easier if you had just asked for that format in the first place.
myData = load('example.mat');
myOutputData = nan(2,length(myData.pn));
for k = 1:length(myData.pn)
data = myData.pn{k};
myOutputData(1,k) = str2double(data(:,1)');
if size(data,2) == 2
myOutputData(2,k) = str2double(data(:,2)');
end
end
Dear Geoff,
I really appreciate, veryyyyygoodddddddddd
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
