フィルターのクリア

Why am I getting zeros

2 ビュー (過去 30 日間)
olivia
olivia 2023 年 8 月 31 日
コメント済み: Voss 2023 年 8 月 31 日
%Latty:
38
39
37
40
39
36
39
39
38
40
35
37
38
40
40
37
36
36
39
36
40
35
39
35
39
39
35
38
39
38
37
36
35
37
39
40
36
39
39
38
38
36
36
38
36
36
38
35
40
36
36
36
36
37
38
39
36
35
38
40
36
32
Latty=LLARYP.Lat;
a=6378137; %meters
b=6356752; %Meters
fprintf ("Prime Vertical Radius of Curvature\n");
i = 1;
sz = size(Latty);
while i <= sz(1)
Rn(:,1)=(a^2)/(sqrt((a^2)*(cosd(Latty).^2)+(b^2)*(sind(Latty).^2)));
i = i + 1;
end
fprintf("Rn =");
disp (Rn)
%Output
Prime Vertical Radius of Curvature
Rn = 1.0e+06 *
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
6.3841
%%The output I get

採用された回答

Voss
Voss 2023 年 8 月 31 日
Latty = [38; 39; 37; 40; 39; 36; 39; 39; 38; 40; 35; 37; 38; 40; 40; 37; 36; 36; 39; 36; 40; 35; 39; 35; 39; 39; 35; 38; 39; 38; 37; 36; 35; 37; 39; 40; 36; 39; 39; 38; 38; 36; 36; 38; 36; 36; 38; 35; 40; 36; 36; 36; 36; 37; 38; 39; 36; 35; 38; 40; 36; 32];
a=6378137; %meters
b=6356752; %Meters
Your while loop doesn't appear to be necessary; it's performing the exact same calculation multiple times. Maybe you meant this:
i = 1;
sz = size(Latty);
while i <= sz(1)
Rn(i,1)=(a^2)/(sqrt((a^2)*(cosd(Latty(i)).^2)+(b^2)*(sind(Latty(i)).^2)));
i = i + 1;
end
disp(Rn)
1.0e+06 * 6.3862 6.3866 6.3859 6.3870 6.3866 6.3855 6.3866 6.3866 6.3862 6.3870 6.3852 6.3859 6.3862 6.3870 6.3870 6.3859 6.3855 6.3855 6.3866 6.3855 6.3870 6.3852 6.3866 6.3852 6.3866 6.3866 6.3852 6.3862 6.3866 6.3862 6.3859 6.3855 6.3852 6.3859 6.3866 6.3870 6.3855 6.3866 6.3866 6.3862 6.3862 6.3855 6.3855 6.3862 6.3855 6.3855 6.3862 6.3852 6.3870 6.3855 6.3855 6.3855 6.3855 6.3859 6.3862 6.3866 6.3855 6.3852 6.3862 6.3870 6.3855 6.3841
However, you can do the same thing without a loop. (Use ./ for element-wise division.)
Rn = a^2./sqrt(a^2*cosd(Latty).^2+b^2*sind(Latty).^2);
disp(Rn)
1.0e+06 * 6.3862 6.3866 6.3859 6.3870 6.3866 6.3855 6.3866 6.3866 6.3862 6.3870 6.3852 6.3859 6.3862 6.3870 6.3870 6.3859 6.3855 6.3855 6.3866 6.3855 6.3870 6.3852 6.3866 6.3852 6.3866 6.3866 6.3852 6.3862 6.3866 6.3862 6.3859 6.3855 6.3852 6.3859 6.3866 6.3870 6.3855 6.3866 6.3866 6.3862 6.3862 6.3855 6.3855 6.3862 6.3855 6.3855 6.3862 6.3852 6.3870 6.3855 6.3855 6.3855 6.3855 6.3859 6.3862 6.3866 6.3855 6.3852 6.3862 6.3870 6.3855 6.3841
  2 件のコメント
olivia
olivia 2023 年 8 月 31 日
wow thank you so much
Voss
Voss 2023 年 8 月 31 日
You're welcome!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by