1

I have a set e.g.,

set={[1],[1,2,3],[1,2,3],[1]}

However, I need to repeat [1,2,3,..] several times. Lets say I have [1:r] and need repeat the same for n times. Then, it should be in the following form:

set={[1],[1,2,..r], ... ,[1,2,..r],[1]} 

I tried to use

repmat([1:3],1,3)
%   1     2     3     1     2     3     1     2     3

which has repeated elements but in the same array. I need it as 3D format.

1

1 Answer 1

1

Rather than using repmat([1:3], 1, 3) which will repeat 1:3 3 times within the same numeric array, you want to pass the cell array element as the first input to repmat (note the {} surrounding the array).

repmat({1:3}, 1, 3)

%   { [1 2 3], [1 2 3], [1 2 3] }

To create your array from an initial cell array, you could do something like this

r = 3; n = 3;

initial = {1, 1:r, 1};
final = [initial(1), repmat(initial(2), 1, n), initial(3)];

%   { [1], [1 2 3], [1 2 3], [1 2 3], [1] }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.