Problem 830. Fill a zeros matrix
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
Problem Comments
-
9 Comments
In the problem, line 3 "square matrix" should have the "square" removed; plural of index will be indices... Nevertheless I like the problem especially with all those forbidden words.
funny
How can you iterate without a FOR loop?
Solution Comments
Show commentsGroup

Indexing I
- 27 Problems
- 236 Finishers
- Piecewise linear interpolation
- Longest run of consecutive numbers
- Construct an index vector from two input vectors in vectorized fashion
- Getting the indices from a matrix
- First non-zero element in each column
- Return unique values without sorting
- Return a list sorted by number of consecutive occurrences
- intersection of matrices
- Generate N equally spaced intervals between -L and L
- Check if number exists in vector
- Replicate elements in vectors
- We love vectorized solutions. Problem 1 : remove the row average.
- intersection of matrices
- Generate N equally spaced intervals between -L and L
- Create logical matrix with a specific row and column sums
- Return a list sorted by number of consecutive occurrences
- Replicate elements in vectors
- Get the elements of diagonal and antidiagonal for any m-by-n matrix
- Getting the indices from a matrix
- Check if number exists in vector
- Fill a zeros matrix
- Set the array elements whose value is 13 to 0
- Construct an index vector from two input vectors in vectorized fashion
- Joining Ranges
- Remove the two elements next to NaN value
- Reindex a vector
- Longest run of consecutive numbers
- Put two time series onto the same time basis
- Getting logical indexes
- Matrix indexing with two vectors of indices
- middleAsColumn: Return all but first and last element as a column vector
- Return elements unique to either input
- "Low : High - Low : High - Turn around " -- Create a subindices vector
- Return unique values without sorting
- Find the largest value in the 3D matrix
- Specific Element Count
- First non-zero element in each column
Problem Recent Solvers626
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!