필터 지우기
필터 지우기

How to create matrices each containing integers in ascending order up to the value indicated in the parent matrix

조회 수: 6 (최근 30일)
Hello all!
I have a matrix containing 3 numerical variables: A = [10 25 20]
I need to create three matrices each containing integers in ascending order up to the value indicated in the matrix A. i.e.:
A_1 = [1 2 3 4 5 6 7 8 9 10]; A_2 = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15]; A_3 = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20];
Thank you!

채택된 답변

KSSV
KSSV 2017년 7월 3일
A = [10 25 20] ;
iwant = cell(length(A),1) ;
for i = 1:length(A)
iwant{i} = 1:A(i) ;
iwant{i}
end

추가 답변 (1개)

Guillaume
Guillaume 2017년 7월 3일
DO not number variables, ever. Store these obviously related matrices into a single variable that you can index. In this case, a cell array.
A = [10 25 20]
result = arrayfun(@(n) 1:n, A, 'UniformOutput', false)

카테고리

Help CenterFile Exchange에서 Text Data Preparation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by