Nov 25, 2015

f Comment

Fixing Strange Octave/Matlab Warning: "value not equal to 1 or 0 converted to 1"

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:
debug> Y(Y == 0) = 10;
warning: value not equal to 1 or 0 converted to logical 1
warning: called from
svmTrain at line 36 column 9
saveSvmModelForRecognizingDigits at line 23 column 11
debug> typeinfo(Y)
ans = bool matrix
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.
%note Y is a bool matrix; we gotta convert it to a matrix
Y2=0;
%the following for loop is for copying every value from Y to Y2
for i=1:size(Y,1), 
  for j=1:size(Y,2), 
    Y2(i,j)=Y(i,j); 
  end
end
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!
Please leave a comment here!
One Minute Information - by Michael Wen
ADVERTISING WITH US - Direct your advertising requests to Michael