0

I have two matrices of size 100 x 1

A=[a1;a2;a3;...;a100] 
N=[n1;n2;n3;...;n100]

I want to create a matrix of size sum(N) x 1 that has a1 elements of n1, a2 elements of n2 and ...:

enter image description here

How can I do this in MATLAB?

Suever
  • 64,497
  • 14
  • 82
  • 101
Paris
  • 15
  • 4

1 Answers1

0

You can use repelem to repeat each element in A by the corresponding entry in N

A = [1, 2, 3];
N = [3, 2, 1];

output = repelem(A, N);
%   1   1   1   2   2   3
Suever
  • 64,497
  • 14
  • 82
  • 101
  • thank you for your answer. but when I run this method, matlab send a " Undefined function or method 'repelem' for input arguments of type 'double'." error. despite of this method is there any other way? – Paris Apr 11 '17 at 15:20
  • @Paris What version of matlab? – Suever Apr 11 '17 at 15:54
  • See the duplicate I linked which offers alternatives to `repelem` – Suever Apr 11 '17 at 16:00
  • MATLAB version is R2011b. I see the duplicate page, I didn't notice that and thank you very much for your offer, that is completely solving my problem. – Paris Apr 11 '17 at 16:42