Let m be the size of a sequence, where m is even,
How to generate a sequence
A = [ 1 , m/2, m,
2, (m/2 -1), (m/2 +1), (m-1),
3, (m/2 -2), (m/2 +2), (m-2),
.....]

 채택된 답변

KSSV
KSSV 2022년 3월 15일
편집: KSSV 2022년 3월 15일

1 개 추천

m = 10 ;
n = 10 ; % decide till what number you want to end
C1 = (1:n)' ;
C2 = m/2-(0:n-1)' ;
C3 = [m ; m/2+(1:n-1)'] ;
A = [C1 C2 C3]
A = 10×3
1 5 10 2 4 6 3 3 7 4 2 8 5 1 9 6 0 10 7 -1 11 8 -2 12 9 -3 13 10 -4 14

댓글 수: 9

KSSV
KSSV 2022년 3월 15일
Edited the code..
KSSV
KSSV 2022년 3월 15일
You got the logic....try to change it to your desired case.
KSSV
KSSV 2022년 3월 15일
Actually (m-1), (m-2) these elements need to be considered....which I have not considered in the answer. Let me check.
Torsten
Torsten 2022년 3월 15일
편집: Torsten 2022년 3월 15일
Isn't there an m/2 missing in the first line of the matrix
1 , m/2, m/2, m,
instead of
1 , m/2, m,
?
Ammy
Ammy 2022년 3월 15일
@Torsten Yes, it is.
Torsten
Torsten 2022년 3월 15일
편집: Torsten 2022년 3월 15일
m = 10 ;
n = 10 ; % decide till what number you want to end
C1 = (1:n).' ;
C2 = m/2 - (0:n-1).' ;
C3 = m/2 + (0:n-1).';
C4 = m - (0:n-1).';
A = [C1 C2 C3 C4]
Ammy
Ammy 2022년 3월 15일
@Torsten thank you very much, Is there any way to vote your answer, please
Torsten
Torsten 2022년 3월 15일
It's KSSV's solution - only slightly adapted.
But thank you for asking.
Ammy
Ammy 2022년 3월 15일
Yes it is, but sometimes there is an option of voting more than one solution, thank you very much.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2022년 3월 15일

댓글:

2022년 3월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by