Sequencing a matrix with two constant variables and two incremental variables
2 views (last 30 days)
Show older comments
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!
0 Comments
Answers (1)
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);
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!