MATLAB:查找范围内的函数

时间:2016-07-07 21:38:05

标签: matlab find range indices

如何在特定范围内使用find功能。

说,我有一个带有随机值的数组arr1。我有一个开始&我要分析的部分的结束索引(在这个例子中,我想找到当值大于0.8时的第一次出现)

这里如何使用find函数的开始和结束索引以及条件?

例如:

arr1 = rand(1000,1);
start_ind = [100;500;850];
end_ind = [160;620;925];

for i = 1:length(start_ind)
    output = find(arr1(start_ind(i):end_ind(i)) >=0.8); % ????
end 

非常感谢,

1 个答案:

答案 0 :(得分:1)

使用start_ind - 1的第二个参数仅获得第一个匹配项。然后,您可以通过添加arr1 = rand(1000,1); start_ind = [100; 500; 850]; end_ind = [160; 620; 925]; output = zeros(length(start_ind), 1); for i = 1:length(start_ind) output(i) = find(arr1(start_ind(i):end_ind(i)) >=0.8, 1) + start_ind(i) - 1; end

来转移索引
<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
<form class="form-item">
    <div class="cart">
        <!--<input type="submit" value="Add to Cart" />-->

        <!-- First use a button not an input and give it an ID -->
        <button id="btn_add" type="submit">Add to Cart</button>
    </div>
</form>
<script>

    // You can shorten up the ready statement
    //$(document).ready(function(){

    $(function(){

        // Now bind a click handler with button's ID

        // This is an older way of binding in jQuery
        // $("#btn_add").click(function(){

        // Use jQuery's on() instead.
        $("#btn_add").on("click", function(){

            // Change the HTML of the button by getting it by it's new ID
            // button_content.html('Adding...'); //Loading button text

            $("#btn_add").html('Adding...');

            alert("Item added to Cart!"); //alert user
        });
    });
</script>