Why does can't I assign number greater than 1 to a matrix?

조회 수: 3 (최근 30일)
Matthew Gingerich
Matthew Gingerich 2018년 7월 22일
답변: Paolo 2018년 7월 22일
Why is value (2,2) of this matrix getting assigned to 1 instead of 9 in this console output? How can I make it take values greater than 1?
>> myMat = ~eye(3)
myMat =
0 1 1
1 0 1
1 1 0
>> myMat(2,2) = 9
myMat =
0 1 1
1 1 1
1 1 0

채택된 답변

Paolo
Paolo 2018년 7월 22일
~eye(3) returns a logical array. You must convert it to double. Use:
logicalMat = ~eye(3);
myMat = double(logicalMat);
myMat(2,2) = 9;

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

제품


릴리스

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by