行列の各要素の処理について

9 Ansichten (letzte 30 Tage)
朋貴 熊田
朋貴 熊田 am 17 Sep. 2021
Kommentiert: 朋貴 熊田 am 17 Sep. 2021
Aと言うm×n行列がある時に、A行列の各要素で負の値になる所を0の値に変えたいです。
なんとなく、if文で出来るかと思ったので以下のようにやってみたところ
if A<0
A=0
end
このようにやってみても、各要素で見れず出来ませんでした。
行列の各要素でこのような処理が出来る方法をご教授お願いいたします、

Akzeptierte Antwort

Hernia Baby
Hernia Baby am 17 Sep. 2021
indexをご使用ください
A=randi([-3,3],6,5)
A = 6×5
2 0 -3 2 2 2 0 1 1 3 2 3 -3 2 -3 2 0 1 -2 3 1 -1 -2 -2 -3 0 1 3 -2 0
A(A<0)=0
A = 6×5
2 0 0 2 2 2 0 1 1 3 2 3 0 2 0 2 0 1 0 3 1 0 0 0 0 0 1 3 0 0
  1 Kommentar
朋貴 熊田
朋貴 熊田 am 17 Sep. 2021
ご教授ありがとうございます。

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!