Sequencing a matrix with two constant variables and two incremental variables
이전 댓글 표시
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!
답변 (1개)
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);
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!