Info

この質問は閉じられています。 編集または回答するには再度開いてください。

How can I transform two values separted by _ of one colum in two columns?

1 回表示 (過去 30 日間)
Kirsten Purschke
Kirsten Purschke 2019 年 5 月 15 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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,

回答 (4 件)

madhan ravi
madhan ravi 2019 年 5 月 15 日
s='78.5888_2.027'
str2double(regexp(s,'\d+[\.?]\d*','match'))
  6 件のコメント
Kirsten Purschke
Kirsten Purschke 2019 年 5 月 15 日
screenshot
madhan ravi
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
Dawn MacIsaac 2019 年 5 月 15 日
You can also use strsplit in combination with str2double(), but you would have to loop through each row in the table.

Star Strider
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
Kirsten Purschke 2019 年 5 月 15 日
Jeah that works. Thank you!
Star Strider
Star Strider 2019 年 5 月 15 日
My pleasure!
If my Answer helped you solve your problem, please Accept it!

Adam Danz
Adam Danz 2019 年 5 月 15 日
編集済み: Adam Danz 2019 年 5 月 15 日
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.

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by