How to write multiple levels of if-else statements
Show older comments
Hi,
i am trying to write a code for the following:
h(x,y) = h_init, if (X,Y)not equal to Q
h(x,y) = h_init+h_step, if (X,Y)equal to Q
where Q is:
-3/4<X<3/4, and
[(1/sqrt3)X+(K-.5)*sqrt(3)/2]<Y<[X/sqrt3 + sqrt3/4], if Y>0 OR
[-X/sqrt3-sqrt3/4]<Y<[-X/sqrt3+(0.5-K)sqrt3/2], if Y<0
This is my current code but it is giving me errors:
K=0.2; % ratio of length of inner and outer triangles 0<K<1
R_P=sqrt((16*delta_sq*r_1^2)/(3*sqrt(3)*(1-K^2)));
h_step = 5e-06; % step microasperity depth
nHi=max(size(X));
nHj=max(size(Y));
% flat step condition
for ii=1:nHi,
for jj=1:nHj,
if (X(ii)/R_P)>(-3/4) & (X(ii)/R_P)<(3/4),
if ((Y(ii)/R_P)>0),
(Y(ii)/R_P)>((X(ii)/(R_P*sqrt(3)))+(((K-0.5)*sqrt(3))/2)) & (Y(ii)/R_P)<((X(ii)/(R_P*sqrt(3)))+(sqrt(3))/4),
h(ii,jj)=h_init+h_step;
if ((Y(ii)/R_P)<0),
(Y(ii)/R_P)>((-(X(ii))/(R_P*sqrt(3)))-(sqrt(3))/4) & (Y(ii)/R_P)<((-(X(ii))/(R_P*sqrt(3)))+(((0.5-K)*sqrt(3))/2)),
h(ii,jj)=h_init+h_step
elseif (X(ii)/R_P)<(-3/4) & (X(ii)/R_P)>(3/4),
h(ii,jj)=h_init;
end
end
end
end
end
I think the mistake lies with the different levels of the if-condition. The code provided gives me errors as some parts of the domain are not defined, as per Matlab error. Any help will be appreciated.
1 Comment
Accepted Answer
More Answers (0)
Categories
Find more on Targeting FPGA & SoC Hardware in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!