Build array from for loop

조회 수: 72 (최근 30일)
david crowley
david crowley 2021년 9월 10일
답변: Jan 2021년 9월 10일
I have a for loop that generates an array (newdd) that changes in length in each iteration.
How do create a new variable (array) that combines each array (newdd) generated from the loop so that the output is one long array of all newdd combined?

채택된 답변

Jan
Jan 2021년 9월 10일
n = 100;
c = cell(1, n);
for k = 1:n
c{k} = rand(1, randi(10));
end
result = cat(2, c{:});
This avoids an iteratively growing output vector, because this would need a lot of ressources.

추가 답변 (0개)

카테고리

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