Concatenate two double arrays into a n x 1 cell array using matlab -
i have n x 1
double array.
a = [1234; 1235; 1236; 1237; 1238];
and double scalar.
b = [4567]
i want combine (concatenate) these make n x 1
cell array looks this,
c = [1234 4567; 1235 4567; 1236 4567; 1237 4567; 1238 4567];
try one-liner:
out = mat2cell([a,repmat(b,numel(a),1)],ones(numel(a),1),2)
sample run:
a = [1234; 1235; 1236; 1237; 1238]; b = [4567];
results:
out = [1x2 double] [1x2 double] [1x2 double] [1x2 double] [1x2 double]
if want 1xn
cells, transpose output
out = out.' %//' out = [1x2 double] [1x2 double] [1x2 double] [1x2 double] [1x2 double]
Comments
Post a Comment