Hello guys, I want to check each element of a vector v and if any element in the vector is equal to or in between -0.9 and 0.9, then i want to calculate d using one formula and if the element is not between -0.9 and 0.9, I want to use another formula. Also after each iteration, I want to display the variable d.
So for example if my vector v = -1:0.1:1 then the result should be
0.35
0.3354
0.3354
0.3354
0.3354
0.3354
0.3354
0.3354
0.3354
0.3354
0.3354
0.3354
0.3354
0.3354
0.3354
0.3354
0.3354
0.3354
0.3354
0.35
but for me, the 0.35 value is not being displayed but for every iteration, the same value 0.3354 is being displayed .
v = -1 :0.1: 1;for i= 1:length(v) if any(v >= -0.9 & v<=0.9) d = sqrt((h^2)+(s^2));if any(v<-0.9 & v>0.9) g= sqrt(s^2 + (v-0.9)^2); d = sqrt(g^2 + h^2);end enddisp(d);end
Best Answer