convert char to double
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
I really appreciate someone tell me how can I convert attached file to double.
Thanks in advance.
채택된 답변
Geoff Hayes
2020년 4월 8일
0 개 추천
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
Farshid Daryabor
2020년 4월 8일
Please check array 16 "numericData(16)" it is array I have problem. Please take a look at myData.pn(16).
Geoff Hayes
2020년 4월 8일
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?
Farshid Daryabor
2020년 4월 8일
Are you expecting two numbers like 6901962 and 6901959? YES, I expect to be in two different column
Geoff Hayes
2020년 4월 8일
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.
Farshid Daryabor
2020년 4월 9일
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.
Farshid Daryabor
2020년 4월 9일
should be in two row exactly same form of lon and lat
Geoff Hayes
2020년 4월 9일
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
Farshid Daryabor
2020년 4월 9일
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)
