필터 지우기
필터 지우기

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...
  댓글 수: 1
Ihiertje
Ihiertje 2017년 2월 1일
Thanks a lot! This works for me.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by