Replacing values in a matrix

1 view (last 30 days)
RickJ
RickJ on 5 Apr 2020
Commented: RickJ on 5 Apr 2020
For a very large matrix of (1500000, 6) I wish to change the first 10 values in column 1 to 1, the next 10 values to 2, the next 10 to 3, etc.
Using for example:
X = randi([0,1],[1500000,6]);
To create the table.

Accepted Answer

Tommy
Tommy on 5 Apr 2020
Try this:
N = 1500000;
X = randi([0,1],[N,6]);
i = 1:N/10;
X(:,1) = repelem(i,10);
  1 Comment
RickJ
RickJ on 5 Apr 2020
That's it! Incredible, thank you so much!!!

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!