help me edit the code. I would appreciate it if you simplify the code. (Function code)

3 次查看(过去 30 天)
read_cal_output code file;
function [convergence_time, rms_values,north,east,up ]= read_cal_output(yakinsama_siniri,ref_coor,filename)
%%%%% written by Sinan BİRİNCİ -----12.05.2023
% clc;
% clear ;
% tic;
%filename ='results_float.txt';
t =struct('line',{});
dosya =fopen (filename,'r');
if dosya<0 % dosya değişkenin değeri sıfırdan küçük olursa girilen dosya ismi yanlıştır...HATA MESAJI
error('Girmiş olduğunuz dosya ismi yanlıştır... DOSYA BULUNAMADI...!')
end
satir = fgets(dosya);%fegts komutuyla dosyanın ilk satırını okuyup satır değişkenine atadık.
i=1;%t(i).line ilerlemesi sağlamak için...
while ischar(satir)%satır kontrolü yapıldı.(verinin sonunda durması için)
t(i).line =satir ; %yukarıda okunan ilk satır değerini t(i).line a atadık.
if length(t(i).line)>17 && strcmp(cellstr(t(i).line(1:17)),'# (1) (2) (3)')% atanılan satır değerinden headerin sonunu kestridik.
lastHeaderLine=i;
end
satir=fgets(dosya);%otomatik ikinci satır okuyup döngünün içinde başa döndü ve t(i).line'ı 2.verisini atadı.
i=i+1;
end
fclose(dosya);
sayac=1;
for jj=lastHeaderLine+1:length(t)
results(sayac,:)= cell2mat(textscan(t(jj).line(1:70),'%f %f %f %f %f %f'));
sayac=sayac+1;
end
recPosition5=ref_coor; %[4213605.371;2370561.966;4146265.205];
%[Enlem1,Boylam1,dd]=xyx2eby(recPosition5);
[Enlem1,Boylam1,hellp]=XYZ2ebhell(recPosition5);
for s=1:length(results)
X=results(s,4:6)';
deltaX2=X(1:3,1)-recPosition5;
Rtopo2=[-sind(Enlem1)*cosd(Boylam1) -sind(Enlem1)*sind(Boylam1) cosd(Enlem1);
-sind(Boylam1) cosd(Boylam1) 0 ;
cosd(Enlem1)*cosd(Boylam1) cosd(Enlem1)*sind(Boylam1) sind(Enlem1)]; % toposentrik koordinatlara geçiş için R matrisi
toposentrik2=Rtopo2*deltaX2; % toposentrik koordinatlarının elde edilmesi (north, east, up )
north2=toposentrik2(1,1);
east2=toposentrik2(2,1);
up2=toposentrik2(3,1);
total_error=sqrt(north2^2+east2^2+up2^2);
north(s,1)=north2; east(s,1)=east2; up(s,1)=up2; total(s,1)=total_error;
end
%yakinsama_siniri=0.10;
yak_epok=NaN;
for d=1:length(total)
if total(d,1)<yakinsama_siniri && isempty(find(total(d+1:end,1)>yakinsama_siniri, 1 ))
yak_epok=d;
break;
end
end
if isnan(yak_epok)
rms_values=[NaN;NaN;NaN;NaN];
convergence_time=yak_epok;
elseif ~isnan(yak_epok)
rms_north=rms(north(yak_epok:end));
rms_east=rms(east(yak_epok:end));
rms_up=rms(up(yak_epok:end));
rms_3D=rms(total(yak_epok:end));
rms_values=[rms_north;rms_east;rms_up;rms_3D];
convergence_time=yak_epok;
end
end
XYZ2ebhell code file;
function [enlem,boylam,hellp]=XYZ2ebhell(position)
a=6378137;
b=6356752.3141;
c=6399593.62586;
f=1/298.257222101;
ekare=0.00669438002290;
eussukare =0.00673949677548;
X=position(1,1);%X koordinatı
Y=position(2,1);%Y koordinatı
Z=position(3,1);%Z koordinatı
deger1=(Z/(sqrt(X^2+Y^2)))*(1+(ekare/(1-ekare)));
enlem0(1,1)=atan(deger1)*180/pi;
sayac=1;
while 1
sayac=sayac+1;
N=c/(sqrt(1+eussukare*(cosd(enlem0(sayac-1)))^2));
deger2=(Z/(sqrt(X^2+Y^2)))*(1+((ekare*N*sind(enlem0(sayac-1)))/Z));
enlem0(sayac,1)=atan(deger2)*180/pi;
kontrol= enlem0(sayac,1)-enlem0(sayac-1,1);
if abs(kontrol)<0.000000001
break;
end
end
boylam=(atan(Y/X))*180/pi;
enlem=enlem0(end,1);
hellp=(sqrt(X^2+Y^2))/cosd(enlem)-N;
end
  4 个评论
Steven Lord
Steven Lord 2024-1-24
The atand and atan2d functions would help avoid the "magic number" 180/pi. The hypot function could also be useful.
But I agree with Walter. I'd identify the main purpose of each "chunk" of code and put that as a comment before that chunk. Treat that as the outline of a paper you're planning to write, as steps in a recipe, or the pictures in the instructions of a LEGO set that show which pieces are involved at that step.
Then if what each of those chunks of code does to implement that purpose is unclear, then I'd add additional comments (mainly about why the code does what it does; the how can often be understood from the documentation for the functions being used.)
Rik
Rik 2024-1-25
You might also want to contact the original author of the file to ask for an explanation. You should have already contacted them to ask for permission to post their code here.

请先登录,再进行评论。

回答(0 个)

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by