Borrar filtros
Borrar filtros

Select specific data text file

1 visualización (últimos 30 días)
Ihiertje
Ihiertje el 1 de Feb. de 2017
Comentada: Ihiertje el 1 de Feb. de 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.

Respuestas (1)

KSSV
KSSV el 1 de Feb. de 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 comentario
Ihiertje
Ihiertje el 1 de Feb. de 2017
Thanks a lot! This works for me.

Iniciar sesión para comentar.

Categorías

Más información sobre Data Import and Export en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by