Problem with multiple if conditions....
Afficher commentaires plus anciens
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 commentaires
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
le 15 Sep 2014
Adam
le 16 Sep 2014
Yep. That ensures mutual exclusivity at least.
Jules Ray
le 16 Sep 2014
Modifié(e) : per isakson
le 5 Sep 2015
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Graphics Object Properties dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!