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 173207

Submitted on 5 Dec 2012 by Abdelhak ARESMOUK

Correct

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

Test Suite

Test
Code Input and Output
1
Pass
 
%% Test first example
value = -13;
row = 2;
col = 3;
B =  [0     0     0
      0     0   -13];
assert(isequal(your_fcn_name(value,row,col),B))
filetext = fileread('your_fcn_name.m');
assert(isempty(strfind(filetext, 'zeros')),'zeros forbidden')
assert(isempty(strfind(filetext, 'for')),'for forbidden')
assert(isempty(strfind(filetext, 'repmat')),'repmat forbidden')
assert(isempty(strfind(filetext, 'ones')),'ones forbidden')
assert(isempty(strfind(filetext, 'while')),'while forbidden')
assert(isempty(strfind(filetext, 'sparse')),'sparse forbidden')

                    
2
Pass
 
%% Test second example
value = 2012;
row = [ 2 3 3 5 ];
col = [ 1 1 4 4 ];
C =    [ 0           0           0           0
          2012           0           0           0
          2012           0           0        2012
             0           0           0           0
             0           0           0        2012];
assert(isequal(your_fcn_name(value,row,col),C))
filetext = fileread('your_fcn_name.m');
assert(isempty(strfind(filetext, 'zeros')),'zeros forbidden')
assert(isempty(strfind(filetext, 'for')),'for forbidden')
assert(isempty(strfind(filetext, 'repmat')),'repmat forbidden')
assert(isempty(strfind(filetext, 'ones')),'ones forbidden')
assert(isempty(strfind(filetext, 'while')),'while forbidden')
assert(isempty(strfind(filetext, 'sparse')),'sparse forbidden')

                    
3
Pass
 
%% zeros
I = [ 2 3 3 5 1 4 9 2 3 9 ];
J = [ 1 1 4 4 5 5 6 8 8 9 ];
assert(isequal(your_fcn_name(0,I,J),zeros(9)))
filetext = fileread('your_fcn_name.m');
assert(isempty(strfind(filetext, 'zeros')),'zeros forbidden')
assert(isempty(strfind(filetext, 'for')),'for forbidden')
assert(isempty(strfind(filetext, 'repmat')),'repmat forbidden')
assert(isempty(strfind(filetext, 'ones')),'ones forbidden')
assert(isempty(strfind(filetext, 'while')),'while forbidden')
assert(isempty(strfind(filetext, 'sparse')),'sparse forbidden')

                    
4
Pass
 
%% another one
L = [ 2 3 3 5 1 4 9 2 3 9 ];
M = [ 1 1 4 4 5 5 6 8 8 9 ];
sol =[  0     0     0     0     1     0     0     0     0
     1     0     0     0     0     0     0     1     0
     1     0     0     1     0     0     0     1     0
     0     0     0     0     1     0     0     0     0
     0     0     0     1     0     0     0     0     0
     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     1     0     0     1];
assert(isequal(your_fcn_name(1,L,M),sol))
filetext = fileread('your_fcn_name.m');
assert(isempty(strfind(filetext, 'zeros')),'zeros forbidden')
assert(isempty(strfind(filetext, 'for')),'for forbidden')
assert(isempty(strfind(filetext, 'repmat')),'repmat forbidden')
assert(isempty(strfind(filetext, 'ones')),'ones forbidden')
assert(isempty(strfind(filetext, 'while')),'while forbidden')
assert(isempty(strfind(filetext, 'sparse')),'sparse forbidden')

                    
5
Pass
 
%% Last example
I = [ 2 3 3 5 1 4 9 2 3 9 ];
J = [ 1 1 4 4 5 5 6 8 8 9 ];
Z=[
           0           0           0           0        1999           0           0           0           0
        1999           0           0           0           0           0           0        1999           0
        1999           0           0        1999           0           0           0        1999           0
           0           0           0           0        1999           0           0           0           0
           0           0           0        1999           0           0           0           0           0
           0           0           0           0           0           0           0           0           0
           0           0           0           0           0           0           0           0           0
           0           0           0           0           0           0           0           0           0
           0           0           0           0           0        1999           0           0        1999
];
assert(isequal(your_fcn_name(1999,I,J),Z))
filetext = fileread('your_fcn_name.m');
assert(isempty(strfind(filetext, 'zeros')),'zeros forbidden')
assert(isempty(strfind(filetext, 'for')),'for forbidden')
assert(isempty(strfind(filetext, 'repmat')),'repmat forbidden')
assert(isempty(strfind(filetext, 'ones')),'ones forbidden')
assert(isempty(strfind(filetext, 'while')),'while forbidden')
assert(isempty(strfind(filetext, 'sparse')),'sparse forbidden')