Problem with multiple if conditions....
이전 댓글 표시
Hello there:
I have a code composed of 4 if, this are the condition for the xlim of plots that follow the condition. There are 4 situations that i name a=1, a=2, a=3, a=4. Each satisfy certain characteristics of the 2x2 matrix l, which is a line formed by two points :
figure(2)
clf
subplot(2,1,1)
hold on
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%ANGULAR CONDITIONS in the cartesian plane for a line (l)
for i=min(shore):max(shore)
plot(dp(shore==i,3),dp(shore==i,4),'.','color',[1/i 1/i 1/i],'markersize',20)
j(i,1)=i;
end
%%%%%%%%%%%%%%%%%%%%%
if l(1,1)>l(1,2) && l(2,1)>l(2,2) %situation 1
a=1
xlim([0 dkm]) %positive quadrant
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%
if l(1,2)>=l(1,1) && l(2,1)>=l(2,2) %situation 2
a=2
xlim([-dkm 0]) %negative quadrant
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%
if l(1,2)>=l(1,1) && l(2,2)>=l(2,1) %situation 3
a=3
xlim([0 dkm]) %positive quadrant
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if l(1,1)>=l(1,2) && l(2,2)>=l(2,1) %situation 4
a=4
xlim([-dkm 0])
end
legend(num2str(j),'location','eastoutside')
errorbar(dp(:,3),dp(:,4),(dp(:,5)),'ok')%,'o','color',[1/10*i 1/10*i 1/i],'markersize',20)
box on
ylabel('elevation')
xlabel('along profile distance'
however, the if conditions doesn't work properly, in all the runs, only the a=3 condition is used, even if this not satisfy the condition. This is not logic. How can i do to write well this code?. Should i nest the if's?
any help or idea is appreciated... cheers
댓글 수: 4
Use 'elseif' if only one should happen, although if they are mutually exclusive conditions it shouldn't make a difference. I guess they are not.
In your current case all you can tell from the final state of a being 3 is that the 4th condition never matched and the 3rd condition always does. It may match 1 or 2 also, but then matching 3 over-rides that.
Why does case 1 have > while all the other cases have >= ?
Jules Ray
2014년 9월 15일
Adam
2014년 9월 16일
Yep. That ensures mutual exclusivity at least.
Jules Ray
2014년 9월 16일
편집: per isakson
2015년 9월 5일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Graphics Object Properties에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!