Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Solution 127613

Submitted on 14 Aug 2012 by Khaled Hamed

Correct

11Size
This is the leading solution.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

This solution is outdated. To rescore this solution, log in.

Test Suite

Test
Code Input and Output
1
Pass
 
%%
m=ones(4,'uint16');
bmv = bitmask(m);
assert(isinteger(bmv),sprintf('Non-Integer return'))
assert(isequal(bmv,[255 255]))
{Warning: Size vector should be a row vector with integer
elements.}
{> In bitmask at 5
  In verifyCode>evaluateCode at 189
  In verifyCode at 40
  In fevalJSON at 14}
{Warning: Size vector should be a row vector with integer
elements.}
{> In bitmask at 5
  In verifyCode>evaluateCode at 189
  In verifyCode at 40
  In fevalJSON at 14}
2
Pass
 
%%
m=zeros(4,'uint16');
m(1)=1;
m(16)=1;
bmv = bitmask(m);
assert(isequal(bmv,[128 1]),[sprintf('Expected [128 1] saw: ') sprintf('%i ',bmv)])
{Warning: Size vector should be a row vector with integer
elements.}
{> In bitmask at 5
  In verifyCode>evaluateCode at 189
  In verifyCode at 40
  In fevalJSON at 14}
{Warning: Size vector should be a row vector with integer
elements.}
{> In bitmask at 5
  In verifyCode>evaluateCode at 189
  In verifyCode at 40
  In fevalJSON at 14}
3
Pass
 
%%
m=zeros(3,'uint16');
m(8)=1;
m(9)=1;
bmv = bitmask(m);
assert(isequal(bmv,[1 128]))
{Warning: Size vector should be a row vector with integer
elements.}
{> In bitmask at 5
  In verifyCode>evaluateCode at 189
  In verifyCode at 40
  In fevalJSON at 14}
{Warning: Size vector should be a row vector with integer
elements.}
{> In bitmask at 5
  In verifyCode>evaluateCode at 189
  In verifyCode at 40
  In fevalJSON at 14}
4
Pass
 
%%
%Duplicity test
m=randi(65535,[8 4],'uint16');
for i=1:12
 m(randi(32))=0;
end
bmv = bitmask(m);
mb=m>0;
bmv_exp=[128 64 32 16 8 4 2 1]*mb;
assert(isequal(bmv,bmv_exp))
{Warning: Size vector should be a row vector with integer
elements.}
{> In bitmask at 5
  In verifyCode>evaluateCode at 189
  In verifyCode at 40
  In fevalJSON at 14}
{Warning: Size vector should be a row vector with integer
elements.}
{> In bitmask at 5
  In verifyCode>evaluateCode at 189
  In verifyCode at 40
  In fevalJSON at 14}
5
Pass
 
%%
% Load aviris file Layer 1 ; 1.8MB mat file
tic % approx 2.5 sec to write and load
urlwrite('http://tinyurl.com/matlab-avmofL001','aviris_moffett_L001.mat');
toc
load('aviris_moffett_L001.mat');
toc
% Array variable is L001
%Files also posted are L010,L023,L157, and L158 with same tinyurl format
% L010 and L023 have high contrast L157 and L158 are in atmospheric notch
bmv=bitmask(L001);
% L001 (1:8) [1271 1259 1271 0 0 0 0 0]
assert(isequal(bmv(1),224),sprintf('Expected 224 saw: %i',bmv(1)))
assert(isequal(bmv(181097),0),sprintf('Expected 0 saw: %i',bmv(181097)))
assert(isequal(bmv(90800),255),sprintf('Expected 255 saw: %i',bmv(90800)))
Elapsed time is 2.757306 seconds.
Elapsed time is 3.511560 seconds.
{Warning: Size vector should be a row vector with integer
elements.}
{> In bitmask at 5
  In verifyCode>evaluateCode at 189
  In verifyCode at 40
  In fevalJSON at 14}
{Warning: Size vector should be a row vector with integer
elements.}
{> In bitmask at 5
  In verifyCode>evaluateCode at 189
  In verifyCode at 40
  In fevalJSON at 14}