Maximum value is incorrect
조회 수: 2 (최근 30일)
이전 댓글 표시
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)
댓글 수: 0
채택된 답변
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!