Change 1 to -1 in a matrix
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi to all the members, I have a 4 X 4 Matrix of one i.e ones(4). I want to change all the elements from 1 to -1 randomly in the matrix. BUT Only one element should change at a time from 1 to -1. That it the 1 changes to -1 sixteen times as we have sixteen elements in the matrix.
댓글 수: 0
채택된 답변
Adam
2016년 9월 26일
m = ones(4);
r = rand(4) - 0.5;
m = m .* sign( r );
is one of many ways to do it.
댓글 수: 2
참고 항목
카테고리
Help Center 및 File Exchange에서 Discrete Math에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!