How to read .XY file?
78 次查看(过去 30 天)
显示 更早的评论
i've got a file with ext .xy that i want to read, cant attached it here as it is not supported here. it looks liek that:
7004825,RMS:30.78,No:1082.
20.00000000,2.60350425E-02
25.00000000,4.05571833E-02
30.00000000,5.82764596E-02
35.00000000,7.92009458E-02
40.00000000,1.03343524E-01
45.00000000,1.30721480E-01
50.00000000,1.61356464E-01
55.00000000,1.61643982E-01
60.00000000,1.61960006E-01
65.00000000,1.62304759E-01
after that there is a one empty line and it repeats with diffrent numbers.
i want to read 1st line with info and then read 2 columns.
how do i do that? ive tried using this:
fid = fopen(file);
C = textscan(fid, '%s %s %s %d %d', 'HeaderLines',1,'Delimiter',',','EmptyValue',0);
fclose(fid);
Hz = C{4};
disp(Hz)
y = C{5};
disp(y)
but it will read the 1st line with columns and i dont want that.
i need to work with .xy files, but for help i manually converted it and attached.
0 个评论
采纳的回答
Chunru
2022-7-26
编辑:Chunru
2022-7-26
file='random_x.txt';
fid = fopen(file, 'rt');
i=1;
s1 = '';
while ~feof(fid)
s{i} = [s1 fgetl(fid)]; % 1st line
[xy{i}, n] = fscanf(fid, '%f, %f', inf); % xy
if mod(n, 2)==1
s1 = [num2str(xy{i}(end)) ','];
end
xy{i} = reshape(xy{i}(1:floor(n/2)*2), 2, []);
i = i+1;
end
fclose(fid);
s
xy
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!