我的代码是:
T=[0:0.1:24];
omega=((12-T)/24)*360;
alpha = [0:1:90];
latitude=35;
delta=[-23.45:5:23.45];
sind(alpha)=sind(delta).*sind(latitude)+cosd(delta).*cosd(latitude).*cosd(omega)
cosd(phi)=(sind(alpha).*sind(latitude)-cosd(delta))./(cosd(alpha).*cosd(latitude))
alpha表示我的y轴,是0到90度之间的角度。 phi代表我的x轴,并且是-120到+120之间的角度。整体结果应该看起来像半正弦波。
每当我尝试输入最后一行时,我都会得到错误,说明内部矩阵尺寸必须一致。所以我尝试在我的矩阵上使用reshape来处理我定义的变量,以便它们起作用。但后来我得到'??? ???下标索引必须是实数正整数或逻辑。'
每次定义一组新的变量以便将它们与方程一起使用时,必须重新整形我的矩阵似乎非常繁琐。这些变量用于定义我的轴范围,是否有更好的方法可以将它们布局,或者是一个自动命令来确保它们每次都有效?
我想使用像
之类的东西将alpha和phi绘制成图形plot(alpha,phi)
但是无法克服这些错误?我不能只使用一个命令,如定义x轴[0:90],定义y轴[-120:120]或其他什么?我花了太多时间在这个问题上,找不到解决方案。我只是想绘制图表。有人请帮忙!感谢。
由于
答案 0 :(得分:1)
元素乘法(.*
)和除法./
,而不是矩阵版本:
sind(alpha)=sind(delta).*sind(latitude)+cosd(delta).*cosd(latitude).*cosd(omega)
cosd(phi)=(sind(alpha).*sind(latitude)-cosd(delta))./(cosd(alpha).*cosd(latitude))
但更大的问题是您无法使用小数或非正值进行索引。在得到下标索引错误之前返回代码。指数“必须是真实的正面整数或逻辑”。
答案 1 :(得分:1)
这是一个开始:
% Latitude
L=35;
% Hour Angle
h = [-12:5/60:12];
w = 15*h;
% Initialize and clear plot window
figure(1); clf;
% Plot one day per month for half of the year
for N = 1:30:365/2
% Declination
d = 23.45*sind(360*(284+N)/365);
% Sun Height
alpha = asind(sind(L)*sind(d) + cosd(L)*cosd(d)*cosd(w));
% Solar Azimuth
x = ( sind(alpha)*sind(L)-sind(d) )./( cosd(alpha)*cosd(L) );
y = cosd(d)*sind(w)./cosd(alpha);
phi = real(atan2d(y,x));
% Plot
plot(phi,alpha); hold on;
end
hold off;
grid on;
axis([-180, 180, 0, 90]);
xlabel('Solar Azimuth')
ylabel('Solar Elevation')
函数asind
本身仅限于返回-90到90范围内的值。这意味着你不会得到一个跨越240度的图,就像你链接的图一样。为了使绘图没有+/- 90度的拐点,您需要找到一种推断象限的方法。更新:我添加了余弦项以使用atan2d
获取角度。
希望这足以让您了解如何使用Matlab获得您所追求的结果。
答案 2 :(得分:0)
我认为你对MATLAB sintax有点困惑(正如nispio所提到的)。也许你想做这样的事情?
T=[0:0.1:24];
omega=((12-T)/24)*360;
alpha = [0:1:90];
latitude=35;
delta=[-23.45:5:23.45];
[o1,d1]=meshgrid(omega,delta);
[a2,d2]=meshgrid(alpha,delta);
var1=sind(d1(:)).*sind(latitude)+cosd(d1(:)).*cosd(latitude).*cosd(o1(:));
var2=(sind(a2(:)).*sind(latitude)-cosd(d2(:)))./(cosd(a2(:)).*cosd(latitude));
plot(var1);hold on;plot(var2);
如果没有,您应该发布算法或伪代码