Select specific data text file
1 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(1 个)
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 Center 和 File Exchange 中查找有关 Convert Image Type 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!