MATLAB Answers

I need to read third coloumn and all rows of text file in matlab. Pls give your suggestions.

2 views (last 30 days)
ROLI JAISWAL
ROLI JAISWAL on 16 Sep 2021
Edited: Chunru on 17 Sep 2021
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
ROLI JAISWAL
ROLI JAISWAL on 17 Sep 2021
XYZ text file containing 100 rows and 3 coloumns is attached
0.732418683 0.534966362 30534.69899
1.465820042 1.07125896 30534.70238
2.20020407 1.608877666 30534.70578
2.935570762 2.147822356 30534.70917
3.671920111 2.688092902 30534.71256
4.40925211 3.229689177 30534.71595
5.147566753 3.772611056 30534.71934
5.886864033 4.316858411 30534.72273
6.627143944 4.862431117 30534.72612
7.36840648 5.409329047 30534.72951
8.110651634 5.957552074 30534.73291
8.853879399 6.507100072 30534.7363
9.59808977 7.057972915 30534.73969
10.34328274 7.610170475 30534.74308
11.0894583 8.163692627 30534.74647
11.83661645 8.718539245 30534.74986
12.58475717 9.274710201 30534.75325
13.33388047 9.832205369 30534.75664
14.08398634 10.39102462 30534.76003
14.83507476 10.95116784 30534.76343
15.58714574 11.51263488 30534.76682
16.34019927 12.07542563 30534.77021
17.09423534 12.63953997 30534.7736
17.84925394 13.20497775 30534.77699
18.60525506 13.77173886 30534.78038
19.36223871 14.33982318 30534.78377
20.12020488 14.90923056 30534.78716
20.87915355 15.4799609 30534.79056
21.63908472 16.05201405 30534.79395
22.39999839 16.6253899 30534.79734
23.16189455 17.20008832 30534.80073
23.92477319 17.77610918 30534.80412
24.6886343 18.35345236 30534.80751
25.45347789 18.93211772 30534.8109
26.21930394 19.51210515 30534.81429
26.98611244 20.09341451 30534.81769
27.7539034 20.67604568 30534.82108
28.5226768 21.25999854 30534.82447
29.29243263 21.84527295 30534.82786
30.0631709 22.43186879 30534.83125
30.83489159 23.01978594 30534.83464
31.6075947 23.60902426 30534.83803
32.38128022 24.19958363 30534.84142
33.15594814 24.79146393 30534.84481
33.93159846 25.38466502 30534.84821
34.70823118 25.97918679 30534.8516
35.48584628 26.5750291 30534.85499
36.26444376 27.17219182 30534.85838
37.04402361 27.77067484 30534.86177
37.82458582 28.37047803 30534.86516
38.6061304 28.97160125 30534.86855
39.38865733 29.57404439 30534.87194
40.17216661 30.17780731 30534.87534
40.95665822 30.7828899 30534.87873
41.74213217 31.38929201 30534.88212
42.52858845 31.99701353 30534.88551
43.31602705 32.60605434 30534.8889
44.10444796 33.21641429 30534.89229
44.89385118 33.82809328 30534.89568
45.68423671 34.44109116 30534.89907
46.47560452 35.05540782 30534.90247
47.26795463 35.67104312 30534.90586
48.06128702 36.28799695 30534.90925
48.85560168 36.90626917 30534.91264
49.65089861 37.52585966 30534.91603
50.44717781 38.1467683 30534.91942
51.24443926 38.76899494 30534.92281
52.04268296 39.39253948 30534.9262
52.8419089 40.01740178 30534.92959
53.64211708 40.64358172 30534.93299
54.4433075 41.27107916 30534.93638
55.24548013 41.89989399 30534.93977
56.04863498 42.53002608 30534.94316
56.85277205 43.16147529 30534.94655
57.65789132 43.79424151 30534.94994
58.46399278 44.42832461 30534.95333
59.27107644 45.06372446 30534.95672
60.07914228 45.70044093 30534.96012
60.8881903 46.3384739 30534.96351
61.6982205 46.97782324 30534.9669
62.50923286 47.61848883 30534.97029
63.32122737 48.26047053 30534.97368
64.13420405 48.90376823 30534.97707
64.94816286 49.54838179 30534.98046
65.76310382 50.19431109 30534.98385
66.57902691 50.84155601 30534.98725
67.39593213 51.49011641 30534.99064
68.21381947 52.13999217 30534.99403
69.03268892 52.79118316 30534.99742
69.85254048 53.44368926 30535.00081
70.67337414 54.09751035 30535.0042
71.4951899 54.75264628 30535.00759
72.31798774 55.40909694 30535.01098
73.14176767 56.06686221 30535.01438
73.96652967 56.72594195 30535.01777
74.79227374 57.38633603 30535.02116
75.61899987 58.04804434 30535.02455
76.44670806 58.71106674 30535.02794
77.27539829 58.2873726 30535.03133

Sign in to comment.

Answers (1)

Chunru
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")
data = 9×3
1.0e+04 * 0.0001 0.0001 3.0535 0.0001 0.0001 3.0535 0.0002 0.0002 3.0535 0.0003 0.0002 3.0535 0.0004 0.0003 3.0535 0.0004 0.0003 3.0535 0.0005 0.0004 3.0535 0.0006 0.0004 3.0535 0.0007 0.0005 3.0535
  2 Comments
Chunru
Chunru on 17 Sep 2021
This is already in the lon-lat-alt format. What do you mean by saying first coloumn and all rows for X?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!