Invorrect number of answers
조회 수: 1 (최근 30일)
이전 댓글 표시
For this script I'm meant to use each value of d - 3 values - with each value of h - 24 answers - hence I should have 72 answers, but I only have 24 answers. Please help:
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(j) = asind(((sind(phi) * sind(delta(i))) + (cosd(phi) * cosd(delta(i)) * cosd(h_a(j)))));
theta(j) = 90 - alpha(j);
end
if h <= 0.5
beta(j) = -acosd((((sind(delta(i)) * cosd(phi)) - (cosd(h_a(j)) * cosd(delta(i)) * sind(phi)))/sind(theta(j))));
else
beta(j) = acosd((((sind(delta(i)) * cosd(phi)) - (cosd(h_a(j)) * cosd(delta(i)) * sind(phi)))/sind(theta(j))));
end
end
댓글 수: 0
답변 (2개)
Walter Roberson
2020년 12월 23일
After your for for j loop, which ends before the if, 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. That is a single value, 24, so you are always writing to beta(24) so you are only ever getting one answer.
You should move the assignment inside the for loop, and you should assign to beta(i,j)
댓글 수: 2
Image Analyst
2020년 12월 23일
Can you please "Accept" an anwer, and/or Vote for them, to give those who helped you "reputation points"? Thanks in advance.
Cris LaPierre
2020년 12월 23일
You are only capturing 1/3 of your data, then. This is because your outer for loop is always overwriting the previous result. This leaves you with just the values calculated in the last loop only.
Also, your if statement will always be false with the given criteria. This is because h is a vector, and the result of your conditional is mixed (~half true, half false). Perhaps you meant to include this inside your inner for loop? That would make more sense, since you index beta using your loop counter j. For your conditional, use h(j).
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!