필터 지우기
필터 지우기

Expanding a double array

조회 수: 4 (최근 30일)
giovanni negro
giovanni negro 2018년 2월 1일
답변: vijaya lakshmi 2018년 2월 8일
Hi Everybody,
I would like to solve this problem in the smartest way.
I have for example this column vector A=[3;5;6;4;...;2] and I would like to obtain another column vector like this B=[1;2;3;1;2;3;4;5;1;2;3;4;5;6;1;2;3;4;....;1;2], so B would be given for every natural number from 1 to every single element of A; an how can I reach this result?
I thought to start like this: B=1:A, but I get only B=[1;2;3]...any idea?
Thanks!

답변 (1개)

vijaya lakshmi
vijaya lakshmi 2018년 2월 8일
Hi Giovanni,
I understand that you want to create a column vector which contains consecutive numbers, from 1 to every single element of A.
In this command "B=1:A", only the first element of A is considered.
You can try the following code snippet, to get the expected result
A=[2;4;3;5];
B=[];
for i=1:length(A)
B=vertcat(B,(1:A(i))');
end

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by