How can I transform two values separted by _ of one colum in two columns?
정보
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
이전 댓글 표시
Hallo,
I have one column with two values separated by _ e.g. '78.5888_2.027'.
The aim is to separate these alue sin two columns making pltotting of value one against two possible.
Thank you fro your help,
댓글 수: 0
답변 (4개)
madhan ravi
2019년 5월 15일
s='78.5888_2.027'
str2double(regexp(s,'\d+[\.?]\d*','match'))
댓글 수: 6
Kirsten Purschke
2019년 5월 15일
madhan ravi
2019년 5월 15일
Upload your table as .mat file.
Kirsten Purschke
2019년 5월 15일
madhan ravi
2019년 5월 15일
Could you post a screenshot? I'm having trouble downloading the file.
Kirsten Purschke
2019년 5월 15일
madhan ravi
2019년 5월 15일
편집: madhan ravi
2019년 5월 15일
cell2mat(cellfun(@(x)str2double(regexp(x,...
'\d+[\.]?\d*','match')),...
table2cell(T),'un',0)) % where T is n by 1 table assuming from the picture
Dawn MacIsaac
2019년 5월 15일
0 개 추천
You can also use strsplit in combination with str2double(), but you would have to loop through each row in the table.
댓글 수: 0
Star Strider
2019년 5월 15일
This seems to work:
D = load('F.mat');
F = D.F;
for k = 1:size(F,1)
d(k,:) = sscanf(F{k},'%f_%f');
end
The loop is necessary because of the nature of ‘F’.
댓글 수: 2
Kirsten Purschke
2019년 5월 15일
Star Strider
2019년 5월 15일
My pleasure!
If my Answer helped you solve your problem, please Accept it!
Here's a one-liner. No loop needed.
xy = cell2mat(cellfun(@str2num, strtrim(regexprep(F,'[^0-9.]',' ')), 'UniformOutput', false));
xy(:,1) These are your x coordinates
xy(:,2) These are your y coordinates
Tested on your mat file.
댓글 수: 0
이 질문은 마감되었습니다.
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!