필터 지우기
필터 지우기

How can I rearrange a vector?

조회 수: 3 (최근 30일)
Jeah MK
Jeah MK 2022년 2월 15일
댓글: Jeah MK 2022년 2월 15일
I have a vector
a = [9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9];
How can I rearrage it to
a = [0 0 0 0 0 4 3 2 1 0 1 2 3 4 0 0 0 0 0];
Thank you!

채택된 답변

Jan
Jan 2022년 2월 15일
편집: Jan 2022년 2월 15일
Some bold guesses of what you want to achieve:
aa = [9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9];
a = aa;
a(a >= 5) = 0
a = aa;
a(~ismember(a, 1:4)) = 0
a = aa;
a(ismember(a, 5:9)) = 0
a = aa;
a([1:5, end-4:end]) = 0
a = aa;
n = numel(a);
a(abs((1:n) - (n + 1)/2) >= 5) = 0
There is an infinite number of methods to produce the wanted output based on the given input. The current explanations are not enough to find the general solution.
  댓글 수: 1
Jeah MK
Jeah MK 2022년 2월 15일
Thank you! The first one works pretty well!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by