MATLAB: How to pass a binary input as an argument to the MESH command in MATLAB

MATLAB

I receive an error when I pass a binary input to the MESH command. For example
executing
A = rand(3,3);
B = A > 0.5;
% B is binary matrix;
mesh(B);
throws the following error.
??? Error using ==> graph3d.surfaceplot.surfaceplot>localConstructor at 92
Invalid input arguments
Error in ==> mesh at 103
hh = graph3d.surfaceplot(x,'FaceColor',fc,'EdgeColor','flat', ...

Best Answer

The MESH command does not take binary inputs directly. However, as a workaround you can typecast the binary inputs into a double before passing it to the MESH command.
A = rand(3,3);
B = A > 0.5;
% B is binary matrix;
mesh(double(B));