Amazon If you use Octave or Matlab you may encounter the following warning when you try to assign an integer value to a matrix cell:
warning: value not equal to 1 or 0 converted to 1
warning: called from
...
Although this is a warning, it is likely to be the cause of your Octave program's bug. Let's see what this error is about and how to fix it.
Although this article is written specifically for Octave, it may apply to Matlab as well. In case you don't know what they are, they are both numerical computing software.
Cause
The cause of this warning is that you are trying to assign a value other than 0 or 1 to a
bool matrix. A bool matrix can only take a value of 0 or 1. Let's see the following trace:
2 | warning: value not equal to 1 or 0 converted to logical 1 |
4 | svmTrain at line 36 column 9 |
5 | saveSvmModelForRecognizingDigits at line 23 column 11 |
As you can see, Y is a bool matrix. But we want a
matrix, not a
bool matrix. A matrix can represent any integer. A bool matrix can only represent a one or a zero.
Solution
Therefore, the solution is to convert the bool matrix to a normal matrix. See the following code.
1 | %note Y is a bool matrix; we gotta convert it to a matrix |
3 | %the following for loop is for copying every value from Y to Y2 |
Now Y2 is a
matrix. You can use Y2.
I know it's a bit stupid, but it works. If you have a better way to create a
matrix feel free to share it with me.
Questions? Let me know!