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)

采纳的回答

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