making an array with element values equal to column position
이전 댓글 표시
I'm trying to make a function which, given an input row and column size M by N, spits out an M by N array that has its element values equal to the position of the column (or row) they are in. For instance, if the dimension is 4 by 3,
A = [1 2 3; 1 2 3; 1 2 3; 1 2 3]
the function would output an array like this one. I would know how to solve this if the numbers of rows and columns are fixed, but I would like to design a function that takes in any input of rows and columns and produces an appropriate array. How would I go about this problem?
답변 (1개)
James Tursa
2018년 6월 4일
result = repmat(1:N,M,1);
카테고리
도움말 센터 및 File Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!