Sequencing a matrix with two constant variables and two incremental variables

2 views (last 30 days)
Hello! I would like to write a short script that will make a 4x(number) matrix consisting of 4 different variables, A,B,M, and N. A starts at 1, B starts at 2, M starts at 3, and N starts at 4. I would like to sequence it so that A and B are constant as M and N reaches a max number i.e. N=100. Once N is at 100, A and B would increase by one and start the cycle again until A is at the max number minus 2. Ideally this would all be put into a matrix that I can later turn into a txt or csv file. I hope this makes sense, I am not much of a programmer so let me know if there is an easy way to do this! Thank you!

Answers (1)

Voss
Voss on 30 Jun 2022
Like this?
max_num = 10; % change max_num to 100 if you want N to go up to 100
A = reshape(ones(1,max_num-3).'+(0:max_num-3),1,[]);
B = A+1;
M = repmat(3:max_num-1,1,max_num-2);
N = M+1;
X = [A; B; M; N];
disp(X);
Columns 1 through 33 1 1 1 1 1 1 1 2 2 2 2 2 2 2 3 3 3 3 3 3 3 4 4 4 4 4 4 4 5 5 5 5 5 2 2 2 2 2 2 2 3 3 3 3 3 3 3 4 4 4 4 4 4 4 5 5 5 5 5 5 5 6 6 6 6 6 3 4 5 6 7 8 9 3 4 5 6 7 8 9 3 4 5 6 7 8 9 3 4 5 6 7 8 9 3 4 5 6 7 4 5 6 7 8 9 10 4 5 6 7 8 9 10 4 5 6 7 8 9 10 4 5 6 7 8 9 10 4 5 6 7 8 Columns 34 through 56 5 5 6 6 6 6 6 6 6 7 7 7 7 7 7 7 8 8 8 8 8 8 8 6 6 7 7 7 7 7 7 7 8 8 8 8 8 8 8 9 9 9 9 9 9 9 8 9 3 4 5 6 7 8 9 3 4 5 6 7 8 9 3 4 5 6 7 8 9 9 10 4 5 6 7 8 9 10 4 5 6 7 8 9 10 4 5 6 7 8 9 10

Categories

Find more on MATLAB in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!