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

2 Ansichten (letzte 30 Tage)
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.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 4 Sep. 2018
Bearbeitet: Walter Roberson am 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.

Weitere Antworten (0)

Kategorien

Mehr zu Data Import and Export finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by