Prev: Developing Matlab GUIs and Linking them with C/C++ Programs
Next: Color Image Enhancement Using Brightness Preserving Dynamic Histogram Equalization N
From: carl on 15 Apr 2010 04:57 I have a vector that I would like to 'copy' into a matrix. By copy I mean copy the vector n times and store each vector in a row in a matrix. Currently I do: v = [10 10 10]; A = ones(4,3); for i=1 : 4 A(i,:) = v; end but is there a corresponding one-liner for this?
From: Jan Simon on 15 Apr 2010 05:40
Dear Carl! > v = [10 10 10]; > A = ones(4,3); > > for i=1 : 4 > A(i,:) = v; > end For this special problem, this works: A = ones(4, 3) * 10 or b = 10; A = b(ones(4, 3)) etc. If [v] has different values, call REPMAT: A = repmat([10, 11, 8], 3, 1) or A = v(ones(1, 4), :) (This is done inside REPMAT also. Look in its source code.) Good luck, Jan |