Select specific data text file

1 次查看(过去 30 天)
Ihiertje
Ihiertje 2017-2-1
评论: Ihiertje 2017-2-1
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.

回答(1 个)

KSSV
KSSV 2017-2-1
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...

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by