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:
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.
Useful in practice !
There is an error in the statement of the problem: the matrix is the smallest that is compatible with the indices, and is not necessarily square.
how about including "regexp" in the forbidden commandlist?
"regexp" should be forbidden in this problem...ps:the forbidden is so powerful that I can put "zeros" word inside my function's comment.:lol
How about forbiding regexp?
I like it
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
Not sure if reshape is allowed. But desciption do not prohibits it.
I am so proud of myself for solving this problem. :)) Nice challenge! :D
Nice challenge. Learned how matrix indices are used
I have completed upto creating zero matrix but can't find anything specific to insert the values! any hints?
Overwrites assert.m
function B = your_fcn_name(value,row,col)
B(row,col)=value;
end
but it shows error pls help me
When row and col are vectors of length n, B(row,col)=value resets all combinations of row(i) and col(j) (a total of n^2 elements); the problem wants just row(i) and col(i) (a total of n elements).
4332 Solvers
Matrix indexing with two vectors of indices
414 Solvers
Get the length of a given vector
1652 Solvers
312 Solvers
595 Solvers