Filter löschen
Filter löschen

Select specific data text file

1 Ansicht (letzte 30 Tage)
Ihiertje
Ihiertje am 1 Feb. 2017
Kommentiert: Ihiertje am 1 Feb. 2017
Hi,
I have the following data in a text file:
ROI "1":
Xi = 294.00 298.00 319.00 312.00 294.00
Yi = 399.00 423.00 419.00 396.00 399.00
ROI "2":
Xi = 227.00 232.00 243.00 236.00 227.00
Yi = 139.00 157.00 159.00 134.00 139.00
ROI "3":
Xi = 298.00 294.00 310.00 313.00 298.00
Yi = 632.00 654.00 658.00 633.00 632.00
I want get the x and y coordinates for each ROI. How do I get these values from the txt.file. I tried different things with textscan, but nothing works so far.
Thank You.

Antworten (1)

KSSV
KSSV am 1 Feb. 2017
fid = fopen('your text file' );
S = textscan(fid,'%s','delimiter','\n') ;
S = S{1} ;
fclose(fid) ;
% Get Xi positions
idxXi = strfind(S, 'Xi');
idxXi = find(not(cellfun('isempty',idxXi)));
% Get Yi positions
idxYi = strfind(S, 'Yi');
idxYi = find(not(cellfun('isempty',idxYi)));
Xi = zeros(length(idxXi),5) ;
Yi = zeros(length(idxYi),5) ;
for i = 1:length(idxXi)
Xi(i,:) = str2num(S{idxXi(i)}(5:end)) ;
Yi(i,:) = str2num(S{idxYi(i)}(5:end)) ;
end
there will be more elegant way...
  1 Kommentar
Ihiertje
Ihiertje am 1 Feb. 2017
Thanks a lot! This works for me.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Data Import and Export finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by