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

Problem 830. Fill a zeros matrix

Created by Aurelien Queffurust

The aim is to fill an array of all zeros given a numerical value and the index of row and columns for this value.

3 Inputs:

- value : unique numerical value to fill the square zero matrix

- row : index of row to fill

- col : corresponding index of column to file

1 Output:

- a matrix of same size which have for each row and col the value specified.

1 st Example:

Fill a 2*3 matrix with the value -13 for the line 2 and column 3 :

value = -13;
row = 2;
col = 3;

output B is:

B =  [0     0     0
      0     0   -13]

2nd Example:

value = 2012;
row = [ 2 3 3 5 ];
col = [ 1 1 4 4 ];

output B is

 B  =
             0           0           0           0
          2012           0           0           0
          2012           0           0        2012
             0           0           0           0
             0           0           0        2012

Restrictions

Sorry , as usual I want to make this problem a little bit harder : Both zeros , for , repmat, ones, while and sparse commands are forbidden.

Problem Group

Solution Statistics

82 correct solutions 106 incorrect solutions
Last solution submitted on Dec 02, 2014

Problem Comments

Solution Comments