comparison of loop and vectorization in matlab

后端 未结 4 789
轮回少年
轮回少年 2021-01-24 04:46

let us consider following code for impulse function

function y=impulse_function(n);
y=0;
if n==0
    y=1;
end
end

this code

>         


        
4条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-24 05:27

    You can write an even simpler function:

    function y=impulse_function(n);
    y = n==0;
    

    Note that this will return y as a type logical array but that should not affect later numerical computations.

提交回复
热议问题