Using condition in Function

조회 수: 1 (최근 30일)
F.O
F.O 2017년 11월 15일
답변: Walter Roberson 2017년 11월 16일

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
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
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개)

카테고리

Help CenterFile Exchange에서 3-D Scene Control에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by