matlab中atan2问题

h1 = linspace(0,2*pi,1000); % 输入h的值
for i = 1:length(h1)
h = h1(i);
t=linspace(0,2*pi,50);
y=sqrt((cos(t)-0.1*cos(t+h)+0.3*(1+0.25*0.3^2)*cos(2*t)).^2+(0.1*sin(t+h)).^2);
imax=find(max(y)==y);
fy=-0.1*sin(t+h);
fx=cos(t)-0.1*cos(t+h)+0.3*(1+0.25*0.3^2)*cos(2*t);
theta=atan2(fy(imax),fx(imax));
hh(i)=h1(i)
yy(i)=theta;
end
plot(hh*180/pi,yy*180/pi,'k')

运行后显示??? In an assignment A(I) = B, the number of elements in B and
I must be the same.
而将atan2换成atan就可以运行出来,不知道什么原因,请问高手给出答案

imax=find(max(y)==y);%% 这一步求出来的imax有两个值,是个1X2的矩阵[1 50]
theta=atan2(fy(imax),fx(imax));%%所以这一步求出来的theta也是个1X2的矩阵
yy(i)=theta;%%这一步等号两侧维度不匹配,所以出错
%%换成atan也不行啊,atan输入变量只能有一个呀?追问

将atan2换成函数atan就可以,只是两者用法不同。imax=find(max(y)==y)难道不是求最大值的下标吗,怎么会有两个最大值呢?请问可不可以给出解决方案,谢谢

追答

你这个数组里有两个一样大的最大值,所以就出来两个结果,根据需要选一个就行了。

温馨提示:答案为网友推荐,仅供参考
相似回答