Fill a zeros matrix - MATLAB Cody - MATLAB Central

Problem 830. Fill a zeros matrix

Difficulty:Rate

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 fill

1 Output:

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

Example 1

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]

Example 2

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: The following commands are forbidden: zeros, for, repmat, ones, while, and sparse.

Solution Stats

31.0% Correct | 69.0% Incorrect
Last Solution submitted on May 07, 2025

Problem Comments

Solution Comments

Show comments
LLMs with MATLAB updated to support the latest OpenAI Models
Large Languge model with MATLAB, a free add-on that lets you access...
2
3

Group

Indexing I Image
Indexing I
  • 27 Problems
  • 237 Finishers

Problem Recent Solvers627

Problem Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Go to top of page