MATLAB: How to make a matrix 256×256 using an operator colon so that its values vary between -100 and 300 in a linear fashion

matrix colon operator

Please help. First part of the exercise was to make a matrix 256×256 using a random numbers generator which was an easy task. I'm clueless about this second part though. Matrix should be the same dimensions 256×256 but made up using only ":" operator and the values in the matrix must vary between -100 and 300 (in a linear way, whatever it means).Thanks in advance

Best Answer

Try this:
increment = (300 - -100) / (256*256 - 1);
rowVector = -100 : increment : 300;
matrix2D = reshape(rowVector, [256,256]);
imshow(matrix2D, []);
axis on;