Why would MATLAB read my .txt file which contains a header and x,y,z columns, as a single column?

3 vues (au cours des 30 derniers jours)
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.

Réponse acceptée

Walter Roberson
Walter Roberson le 4 Sep 2018
Modifié(e) : Walter Roberson le 4 Sep 2018
%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.

Plus de réponses (0)

Catégories

En savoir plus sur Data Import and Export dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by