Why would MATLAB read my .txt file which contains a header and x,y,z columns, as a single column?
3 ビュー (過去 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!