LoginSignup
4
2

More than 5 years have passed since last update.

[matlab]負の値をゼロにするテク

Last updated at Posted at 2015-06-13

解析の待ち時間まーひーなので
今日実装した関数を載せようと思います。

負の値をゼロにするっていう感じなんすけど、
Matlabだと綺麗にかけました。

cutNegativeToZero.m
function Xnonnegative = cutNegativeToZero( X )
%% Xnonnegative = cutNegativeToZero( X )
% @desc: cut off values below zero
% return +1 -> +1
%        -1 -> 0
%
% ex)
% X
% X =
%     0.8252   -1.0582   -0.2725
%     1.3790   -0.4686    1.0984
% common.cutNegativeToZero(X)
% ans =
%     0.8252         0         0
%     1.3790         0    1.0984

    negative = find(X<0);
    X(negative) = zeros(size(negative));
    Xnonnegative = X;
end

シミュレーションで作ったスペクトルにノイズを加えた際に
負の値は取らないはず、とかいうときに使います。

ではでは~

4
2
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2