stdを使用する際に値が0である行列を数えないで正規化したいのですが、何か良い方法はありますか?
ご教授お願いいたします。

2 Kommentare

Hernia Baby
Hernia Baby am 15 Mai 2022
0を除外するという認識でよろしいですか?
朋貴 熊田
朋貴 熊田 am 15 Mai 2022
はいその認識で間違えないです

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Hernia Baby
Hernia Baby am 16 Mai 2022

1 Stimme

std のオプションにNaNを除外する機能がありますので、0をNaNにしましょう
まずはデータを用意します
A = randi([-5 5],9)
A = 9×9
1 4 -4 -3 5 3 2 0 -2 3 -5 3 4 -5 1 4 -5 1 -1 -3 -3 3 -4 -1 1 -1 2 0 -3 2 5 0 -1 3 5 2 -5 1 -3 2 -4 1 -3 2 -2 3 -2 0 3 4 -2 4 -1 1 2 -1 -3 -1 4 4 2 1 -1 -5 4 5 -1 -1 -5 -1 1 -3 4 -2 3 0 -2 -5 -3 -5 0
0をNaNにします
A(A==0) = nan()
A = 9×9
1 4 -4 -3 5 3 2 NaN -2 3 -5 3 4 -5 1 4 -5 1 -1 -3 -3 3 -4 -1 1 -1 2 NaN -3 2 5 NaN -1 3 5 2 -5 1 -3 2 -4 1 -3 2 -2 3 -2 NaN 3 4 -2 4 -1 1 2 -1 -3 -1 4 4 2 1 -1 -5 4 5 -1 -1 -5 -1 1 -3 4 -2 3 NaN -2 -5 -3 -5 NaN
NaNを除外して計算します
std(A,'omitnan')
ans = 1×9
3.5757 3.1535 3.5857 2.8284 4.1036 3.1667 2.7386 3.4200 1.9821

1 Kommentar

朋貴 熊田
朋貴 熊田 am 16 Mai 2022
ご回答ありがとうございます。

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!