MATLAB Answers

0

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

Asked by Matthew Gingerich on 22 Jul 2018
Latest activity Answered by Paolo
on 22 Jul 2018
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

  0 Comments

Sign in to comment.

Products


Release

R2015b

1 Answer

Answer by Paolo
on 22 Jul 2018
 Accepted Answer

~eye(3) returns a logical array. You must convert it to double. Use:
logicalMat = ~eye(3);
myMat = double(logicalMat);
myMat(2,2) = 9;

  0 Comments

Sign in to comment.