Using condition in Function
1 次查看(过去 30 天)
显示 更早的评论
Hei. I have this script:
%% Problem 3 clear all
%a) %DATA for Nazca-Pacific o1=13.6*10^-7 l1=55.6 ph1=-90.1 %DATA for Pacific-Antarctica o2=8.7*10^-7 l2=-64.3 ph2=96 [omeganew,lambdanew,phinew] = geofun( o1,l1,ph1,o2,l2,ph2) %phinew1=phinew1-180
%b) %From Table 2.1 in Fowler Book We choose Africa-North America and Africa- %south America plate pairs because they have a common boundary %Data for Africa-South America SwA=3.1*10^-7 ; %Degree/yr latSA=62.5; %Degree longSA=-39.4; %Data for Africa-North America(The angular velocity is given for North %America relative to Africa and we get for Africa relative to North America %just by change the sign) NwA=2.4*10^-7; AwN=-2.4*10^-7; latAN=78.8; longAN=38.3; [SwN,latSN,longSN] = geofun( SwA,latSA,longSA,AwN,latAN,longAN)
and this function
function [ omeganew,lambdanew,phinew] = geofun( o1,l1,ph1,o2,l2,ph2) %Using known rotation vector data from two pairs of plates to find the %‘unknown’ rotation vector data of another pair of plates (using Table 2.1) 2.1
x=o1*cosd(l1)*cosd(ph1)+o2*cosd(l2)*cosd(ph2) y=o1*cosd(l1)*sind(ph1)+o2*cosd(l2)*sind(ph2) z=o1*sind(l1)+o2*sind(l2) omeganew=sqrt(x^2+y^2+z^2) lambdanew=asind(z/omeganew) phinew=atand(y/x) end
How I will add a condition to the function or where I should put the condition
the condition is If x> 0 then -90<phinew<90 otherwise we subtract 180 from phinew and ifx<0 then the absoloute value of phinew should be greater than 90 otherwise we subtract 180 from phinew
1 个评论
Image Analyst
2017-11-16
Try this http://www.mathworks.com/matlabcentral/answers/13205#answer_18099 so your post won't go into the spam quarantine next time. I've rescued your post this time.
采纳的回答
Walter Roberson
2017-11-16
Use atan2d(y, x) instead of atand(y/x) and you will probably not need to make any angle correction.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 3-D Scene Control 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!