필터 지우기
필터 지우기

Maximum value is incorrect

조회 수: 2 (최근 30일)
Sarah Kneer
Sarah Kneer 2020년 12월 23일
댓글: Sarah Kneer 2020년 12월 23일
I have this code and I want to calculate the maximum value of alpha but it's giving me the minimum value:
phi = 53;
h = 1/24:1/24:1;
d = 100:100:365;
for i = 1:1:length(d)
delta(i) = -23.45 * cosd((360/365) * (d(i)+10));
for j = 1:1:length(h)
h_a(j) = 360 * (h(j)-0.5);
alpha(i,j) = asind(((sind(phi) * sind(delta(i))) + (cosd(phi) * cosd(delta(i)) * cosd(h_a(j)))));
theta(i,j) = 90 - alpha(j);
if h <= 0.5
beta(i,j) = -acosd((((sind(delta(i)) * cosd(phi)) - (cosd(h_a(j)) * cosd(delta(i)) * sind(phi)))/sind(theta(j))));
else
beta(i,j) = acosd((((sind(delta(i)) * cosd(phi)) - (cosd(h_a(j)) * cosd(delta(i)) * sind(phi)))/sind(theta(j))));
end
end
end
a = max(alpha(i,j));
fprintf('%.1f\n',a);
disp(a)

채택된 답변

Walter Roberson
Walter Roberson 2020년 12월 23일
After your for j loop, j will have a value that is the last value assigned to it in the loop; for j=1:1:length(h) will leave j=length(h) after the loop. .... quoting myself from an earlier response to you.
After your for i loop, i will have a value that is the last value assigned to it in the loop; for i=1:1:length(d) will leave i=length(d) after the loop.
So after the loop, i will be length(d) and j will be length(h) . Both of those are scalars.
So when you ask max(alpha(i,j)) you are asking for max() of a scalar. Which is just going to give you the scalar back.
You need to decide whether you want the maximum for each row, or for each column, or over the entire array. Please read the documentation for max() and pay attention to the "dim" parameter.
  댓글 수: 1
Sarah Kneer
Sarah Kneer 2020년 12월 23일
Ohhh, okay that worked, thanks
Could you also guide me on how to calculate the mean of all positive values of aplha?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by