Why would MATLAB read my .txt file which contains a header and x,y,z columns, as a single column?
1 次查看(过去 30 天)
显示 更早的评论
I need to extract xyz data from my text files. However, textscan reads the data into a single column instead of three. Below is the description
FileID = fopen('A.txt','r');
T = textscan(FileID,'%s %f %f','HeaderLines',1,'Delimiter',',');
fclose(FileID);
x = T{1};
y = T{2};
z = T{3};
The text file is attached.
0 个评论
采纳的回答
Walter Roberson
2018-9-4
编辑:Walter Roberson
2018-9-4
%s%f%f with delimiter comma is not even close to being accurate for the file you attached. There is not even a single comma in the file.
FileID = fopen('A.txt','rt');
T = cell2mat( textscan(FileID, '%f%f%f', 'headerlines', 14, 'TreatAsEmpty', 'No Data', 'CollectOutput', true) );
fclose(FileID);
X = 0 : 639; Y = 0 : 479;
T3 = reshape(T(:,3), 640, []);
surf(X, Y, T3.', 'edgecolor', 'none');
xlabel('x'); ylabel('y');
You might prefer to enhance the code to read the 640 and 480 sizes from line 3 or 4 or 9 of the data.
Note: there is available code to read the ZYGO binary format.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import and Export 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!