필터 지우기
필터 지우기

How can I change all the elements in a matrix with value1 to a new value2?

조회 수: 1 (최근 30일)
Michelle Clements
Michelle Clements 2020년 10월 15일
편집: Ameer Hamza 2020년 10월 15일
I have a 78X78 binary matrix. How can I change all the 0s to -1s?

답변 (2개)

Torsten K
Torsten K 2020년 10월 15일
How about this?
m = randi([0,1],78) % 78x78 matrix with random integers in the interval 0..1
m(m==0)=-1 % Substitute all 0's b -1's
Best regards
Torsten

Ameer Hamza
Ameer Hamza 2020년 10월 15일
편집: Ameer Hamza 2020년 10월 15일
Another approach
M; % 78x78 matrix
M_new = 2*M-1;
This will be faster as compared to the indexing approach.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by