MATLAB: Linearly spacing a nX1 matrix

linspacing with condition

Hi!
I have an nx1 matrix. I want to linearly divide the value in each row into 16 columns thus giving me a nx16 linearly spaced matrix.
For a little example let us say I have a=[45; 50] now I want to creat a 2×4 matrix such that the values in consecutive clolumns are linearly spaced and their sum is equal to 45. Could someone help on this one please?

Best Answer

Your problem is still under-specified, and an infinite number of matrices will meet you conditions. Here is one possible solution:
a = [45; 50];
numberColumns = 4;
aMat = a + [0:numberColumns-1];
aMat = (aMat - mean(aMat,2) + a)/numberColumns;