Hello. Im new to Matlab and programming in general so i hope this is not to dumb.
I want to create a main diagonal line to my ones(5) matrix.
The diagonal should contain the first number as 1 and the rest are all 2.
Like this:
1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 1 2
Since we are also supposed to construct bigger matrices of the same kind, i would like to be able to get a "repeat" on the number 2 so i dont have to write all of them out.
I have only been able to construct a diagonal that changes ALL the values with 2 by doing like this:
M = ones(5); u = 2; v = repmat(u,5,1); M = M - diag(diag(M)) + diag(v) 2 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 1 2
So i need some way to get 1 instead of 2 in position (1,1). Is it possible to somehow integrate that into v or somewhere else and still keep the 'repmat'?
Thank you.
Best Answer