I need to read third coloumn and all rows of text file in matlab. Pls give your suggestions.
1 view (last 30 days)
Show older comments
xyz is text file containing 100 rows and 3 columns. The code to convert XYZ Coordinates to geodetic coordinate is discussed below:
j=1;
while(j<100)
X=fopen('xyz.txt(j,1)');
Y=fopen('xyz.txt(j,2)');
Z=fopen('xyz.txt(j,3)');
% Estimate radius of curvature;( WGS84 MODEL is considered)
a = 6378137; % Meter; % Semi-major axis;
f = 1/298.257223563; % Ellipsoid flattening;
b = a*(1-f); % Define Semi-minor axis;
% Estimate auxiliary values;
P = sqrt(X^2 + Y^2);
Theta = atan(Z*a/P*b);
e = sqrt(((a^2) - (b^2))/a^2); % First eccentricity of The Earth;
e2 = sqrt((a^2 - b^2)/b^2); % Second eccentricity of The Earth;
% Initial value of Latitude;
ppi=atan2((Z*(1+e2^2)),P);
N = a / sqrt(1-e^2*sin(ppi).^2); % Prime vertical;
h = (P/cos(ppi)) - N; % Height;
ppi=atan2(Z*(1+e2^2*(N/(N+h))),P);
lamda = (atan2(Y,X))*180/pi;
ppi = ppi*180/pi;
% save llnew_rad.txt
% Display results
disp('Longitutde is :');
disp(lamda);
disp('Latitude is :');
disp(ppi);
disp('Height(Meter) is :');
disp(h);
fprintf('value of j:%d\n',j);
j=j+1;
end
2 Comments
Image Analyst
on 16 Sep 2021
Without having a data file, all I'm going to suggest is to try readmatrix() or importdata(). If you need more help, read the posting guidelines:
and attach a text file with the paperclip icon.
Answers (1)
Chunru
on 17 Sep 2021
You can read all data (xyz.txt contains first part of your data). Then it is up to you to use which column of data.
data = readmatrix("xyz.txt")
2 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!