Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 显示特定值的数组的第一个索引号_Arrays_Matlab_Indexing - Fatal编程技术网

Arrays 显示特定值的数组的第一个索引号

Arrays 显示特定值的数组的第一个索引号,arrays,matlab,indexing,Arrays,Matlab,Indexing,sy是一个1x501阵列,模拟弹丸运动中的垂直位移。 我希望显示低于-4的第一个值的索引号 例如: sy = [0.1 0.3 0.7 1.0 0.7 0.2 -1.0 -3.2 -4.1 -5.3 -6.0]; 我需要一种方法来显示索引号9,因为-4.1是第一个低于-4的值。将sy的每个元素与-4进行比较,找出低于-4的元素:sy。这将返回与sy大小相同的逻辑(布尔)数组。接下来,使用返回第一个为true的元素的索引: find(sy < -4, 1) find

sy
是一个1x501阵列,模拟弹丸运动中的垂直位移。 我希望显示低于-4的第一个值的索引号

例如:

sy = [0.1  0.3  0.7  1.0  0.7   0.2  -1.0  -3.2  -4.1  -5.3  -6.0];

我需要一种方法来显示索引号9,因为-4.1是第一个低于-4的值。

sy
的每个元素与
-4
进行比较,找出低于-4的元素:
sy
。这将返回与
sy
大小相同的逻辑(布尔)数组。接下来,使用返回第一个为true的元素的索引:

find(sy < -4, 1)
find(sy<-4,1)
data = sy(t)
threshold = -4
idx = 0
for i = 1:length(data)
    if data(i) < threshold
        idx = i
        break
    end
end
if idx = 0
    display("Condition not met!")
else
    display("First instance found at index " + idx)
end
data = sy(t)
threshold = -4
idx = find(data < threshold,1)
if length(idx) = 0
    display("Condition not met!")
else
    display("First instance found at index " + idx)
end