在完成练习时,我输入了以下代码。输出为3乘1矢量,由空速、角度和方向组成。空速和角是一个数字的形式,方向是一个字符的形式。
windspeed=[1 3];
groundspeed=[5 3];
north = [0,1];
south = [0,-1];
east = [1,0];
west = [-1,0];
airspeed = 0;
directionans = 0;
angle = 360;
% Begin your code after this line
vertical=[0 1];
airspeed=groundspeed-windspeed;
if (airspeed(1)>0 && airspeed(2)>0)
direction='NE';
elseif all(airspeed==airspeed.*north)
direction='N';
elseif (airspeed(1)<0 && airspeed>0)
direction='NW';
elseif all(airspeed==airspeed.*south)
direction='S';
elseif (airspeed(1)>0 && airspeed(2)<0)
direction='SE';
elseif (airspeed(1)<0 && airspeed(2)<0)
direction='SW';
elseif all(airspeed==airspeed.*west)
direction='W';
elseif all(airspeed==airspeed.*east)
direction='E';
end
if airspeed(2)<0
vertical=south;
elseif airspeed(2)>0
vertical=north;
end
vertical;
angle=acosd(dot(airspeed,vertical)/(norm(airspeed)*norm(vertical)));
[norm(airspeed) direction angle]我想要一个表格中的输出
[50 'NW' 80]相反,结果是
'EZ'这可能是由于错误地将字符赋值给变量造成的。我们能做些什么?
发布于 2017-11-06 02:48:24
不能将数字放入字符数组,也不能将字符放入数字数组。要混合数据类型,需要使用单元格数组,这是用大括号实现的:
>> {norm(airspeed) direction angle}
ans =
1×3 cell array
[50] 'NW' [80]我希望[50 'NW' 80]与[char(50) 'NW' char(80)]相同,后者等于2NWP。
https://stackoverflow.com/questions/47128918
复制相似问题