How do I combine results of a loop in an array?

조회 수: 2 (최근 30일)
Mayla
Mayla 2023년 9월 7일
댓글: Harald 2023년 9월 7일
I am trying to create an array like [1 2 2 3 3 3 4 4 4 4] if n=4 for any n
My first idea was
for m = 1:n
x = [1:m]
x(:)=m
y=[x]
end
But I don't know how I could add all the results to one array.
I am completly new to MATLAB and coding (my second day) so I would be happy if somebody could help me and explain it very easily :)
  댓글 수: 4
Mayla
Mayla 2023년 9월 7일
Thanks :) I got it! Do you have any tipps for practicing and improving with matlab?
Harald
Harald 2023년 9월 7일
Hi Mayla,
As a first step, you may find the free MATLAB Onramp helpful.
Best wishes,
Harald

댓글을 달려면 로그인하십시오.

답변 (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