Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

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

1 visualizzazione (ultimi 30 giorni)
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,

Risposte (4)

madhan ravi
madhan ravi il 15 Mag 2019
s='78.5888_2.027'
str2double(regexp(s,'\d+[\.?]\d*','match'))
  6 Commenti
madhan ravi
madhan ravi il 15 Mag 2019
Modificato: madhan ravi il 15 Mag 2019
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 il 15 Mag 2019
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 il 15 Mag 2019
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’.

Adam Danz
Adam Danz il 15 Mag 2019
Modificato: Adam Danz il 15 Mag 2019
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.

Questa domanda è chiusa.

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by