MATLAB: Repeating a number and then repeating another number using repmat

MATLABrepmat

I need to use 'repmat' twice in B but somehow I need to do it differently. The problem is in B since it does not do exactly what is intended
A = [0:1:125 125:-1:0];
B = [repmat (82, 1, 126) repmat(86, 128, 253)];
so in A, I have
0, 1, 2, 3..... 125, 125, 124, 123, 122..... 0
and in B, I need
82, 82, 82, 82..... 82, 86, 86, 86, 86..... 86
How do I change B so that it works?

Best Answer

Method one: repmat:
>> A = [0:1:125 125:-1:0];
>> B = [repmat(82,1,126),repmat(86,1,126)];
Method two: gradient and sign:
>> B = 84-2*sign(gradient(A));
Method three: diff and cumsum:
>> B = 82+4*cumsum([0,diff(A)==0])