Checking each element in a vector
古いコメントを表示
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
end
disp(d);
end
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Psychology についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!